博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Docker定制私有镜像
阅读量:2337 次
发布时间:2019-05-10

本文共 1849 字,大约阅读时间需要 6 分钟。

手动创建一个nginx+php的镜像

基础镜像Centos7

第一步安装软件

进入根据centos镜像创建的仓库安装nginx和php-fpm

跟新YUM源

yum -y install wget

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

安装nginx和php-fpm

yum -y install nginx php-fpm

安装完成后我们使用supervisor管理进程

yum -y install supervisor

安装完成后 创建nginx进程配置文件

cd /etc/supervisord.d

vi nginx_php.ini

[supervisord]nodaemon=true[program:nginx]command=/usr/sbin/nginx -g "daemon off;"[program:phpfpm]command=/usr/sbin/php-fpm -F -c /etc/php.iniautostart = truestartsecs = 3autorestart = truestartretries = 3user = rootredirect_stderr = falsestuout_logfile_maxbytes = 50MBstdout_logfile_backups = 20

修改nginx配置文件支持php-fpm

vi /etc/nginx/nginx.conf

location ~ .*\.(php|php5)?$ {            fastcgi_pass 127.0.0.1:9000;            fastcgi_index index.php;            include fastcgi.conf;         }

创建一个phpinfo文件

vi /usr/share/nginx/html/index.php

启动supervisor

supervisord

查看supervisor启动状态

supervisorctl status

重启

supervisorctl reload

 

第二部创建镜像

docker commit -m "nginx+php" 752acc398270 nginx_php:V1

  • commit :提交
  • -m :提交时的说明文字
  • 752acc398270 : centos7容器ID
  • nginx_php:创建的镜像名
  • V1 :标签

到这里我们自己私有的nginx+php-fpm镜像就创建完成了

docker images

 

利用刚刚创建的镜像启动一个容器

docker run -it -d -p 80:80 --name nginx_V1 79a9b7c7d728 supervisord

-p:指定端口映射

-d:后台运行

supervisord:进入容器后执行的第一条命令

docker ps

 

-p参数也可以指定IP和协议

指定IP绑定

docker run -it -p 192.168.2.100:6379:6379 --name my_redis redis bash

指定协议

docker run -it -p 6379:6379/udp --name my_redis redis bash

 

宿主机上查看端口

lsof -i :80

通过浏览器测试

 

Cetnos7 容器开启sshd服务

说到systemd,这个套件已经成为主流Linux发行版(比如CentOS7、Ubuntu14+)默认的服务管理,取代了传统的SystemV风格服务管理。systemd维护系统服务程序,它需要特权去会访问Linux内核。而容器并不是一个完整的操作系统,只有一个文件系统,而且默认启动只是普通用户这样的权限访问Linux内核,也就是没有特权,所以自然就用不了

 

解决方法,已特权用户创建容器

docker run -d --name=centos_sshd --privileged=true cf49811e3cdb /usr/sbin/init

docker exec -it 89654d92e1b3 /bin/bash

yum -y install openssh-server

systemctl status sshd

 

 

 

 

 

 

 

 

 

 

 

 

 

转载地址:http://pmepb.baihongyu.com/

你可能感兴趣的文章
java项目之——坦克大战 04
查看>>
java项目之——坦克大战04.1
查看>>
java项目之——坦克大战05
查看>>
java项目之——坦克大战06
查看>>
java项目之——坦克大战09
查看>>
java项目之——坦克大战10
查看>>
java项目之——坦克大战11
查看>>
阿狸面经(牛客网)
查看>>
java常见笔面试题和答案
查看>>
周总结——第一周(9月5号到9月12)
查看>>
2017招商银行笔试01
查看>>
坦克项目总结
查看>>
设计模式之——单例模式
查看>>
ArrayList、Linkedlist和Vector
查看>>
数据库常用
查看>>
简单的学生信息管理系统
查看>>
条理性搭建SSH框架
查看>>
整合Struts和Spring
查看>>
Hibernate和Spring的整合
查看>>
我的校招——同花顺
查看>>