本文共 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
到这里我们自己私有的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/