Docker定制私有镜像

手动创建一个nginx+php的镜像基础镜像Centos7第一步安装软件进入根据centos镜像创建的仓库安装nginx和php-fpm跟新YUM源yum -y install wgetwget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo安装nginx和php-fpm...
摘要由CSDN通过智能技术生成

手动创建一个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.ini

autostart = true
startsecs = 3
autorestart = true
startretries = 3
user = root
redirect_stderr = false
stuout_logfile_maxbytes = 50MB
stdout_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

<?php
  phpinfo();
?>

启动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

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值