supervisor下的Dockerfile的多服务镜像封装操作
编写dockerfile文件
配置yum源
cd /tmp/docker vim dockerfile from rhel7 expose 80 22 # 向外暴露80和22的端口 copy dvd.repo /etc/yum.repos.d/dvd.repo && yum install -y httpd openssh-server openssh-clients supervisor && yum clean all && ssh-keygen -q -t rsa -f /etc/ssh/ssh_host_rsa_key -n "" && ssh-keygen -q -t ecdsa -f /etc/ssh/ssh_host_ed25519_key -n "" && echo root:redhat | chpasswd copy supervisord.conf /etc/supervisord.conf cmd ["/usr/bin/supervisord"]
vim supervisord.conf [supervisord] nodaemon=true [program:sshd] command=/usr/sbin/sshd -d [program:httpd] command=/usr/sbin/httpd
docker build -t rhel7:v3 sending build context to docker daemon 8.192 kb step 1/6 : from rhel7 ---> 0a3eb3fde7fd step 2/6 : expose 80 22 ---> running in 5727c9e984a5 ---> e25a8a0821f7 removing intermediate container 5727c9e984a5 step 3/6 : copy dvd.repo /etc/yum.repos.d/dvd.repo ---> 2d9e8f9648a7 removing intermediate container 62955f7a7a74 step 4/6 : run rpmdb --rebuilddb && yum install -y httpd openssh-server openssh-clients supervisor && yum clean all && ssh-keygen -q -t rsa -f /etc/ssh/ssh_host_rsa_key -n "" && ssh-keygen -q -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -n "" && ssh-keygen -q -t ecdsa -f /etc/ssh/ssh_host_ed25519_key -n "" && echo root:redhat | chpasswd dependency updated: elfutils-libelf.x86_64 0:0.166-2.el7 complete! skipping unreadable repository '///etc/yum.repos.d/rhel7.repo' cleaning repos: docker dvd-rhel cleaning up everything ---> 1cb2f9e34bac removing intermediate container 33cb452dbc8d step 5/6 : copy supervisord.conf /etc/supervisord.conf ---> e8de2ff5ca3c removing intermediate container f219cb2b6a88 step 6/6 : cmd /usr/bin/supervisord ---> running in eddfb3973ad2 ---> dbf4cf5cb116 removing intermediate container eddfb3973ad2 successfully built dbf4cf5cb116
docker run -d --name vm1 -v /tmp/docker/web/:/var/www/html rhel7:v3
docker ps
docker inspect vm1 "networks": { "bridge": { "ipamconfig": null, "links": null, "aliases": null, "networkid": "126902125dd9c54631622845c1a75d656b45023840c57944ec24f4acecf6dc3f", "endpointid": "3d995f01fce91968f59b151a19ba3868292efe0a61c2ef355bcd1eb84bda7248", "gateway": "172.17.0.1", "ipaddress": "172.17.0.2", # 容器的ip "ipprefixlen": 16, "ipv6gateway": "", "globalipv6address": "", "globalipv6prefixlen": 0, "macaddress": "02:42:ac:11:00:02" } }
验证:
curl 172.17.0.2
验证sshd服务:
补充知识:使用dockerfile构建supervisor容器部署项目,cmd ["supervisord","-c","/etc/supervisord.conf"]执行失败
问题描述:
在编写dockerfile创建supervisor容器时,最后一条启动supervisor的命令不起作用 -> cmd ["supervisord","-c","/etc/supervisord.conf"],但是进到容器内部执行supervisord -c /etc/supervisord.conf可以成功运行。
先贴出来dockerfile文件代码
from python:latest workdir /root/ run mkdir /etc/supervisor run mkdir -p /root/projects/logs/gunicorn/ run mkdir -p /root/projects/logs/celery/ run mkdir -p /root/projects/sy_evaluatejkapi/logs/ run echo "deb http://mirrors.aliyun.com/debian/ buster main non-free contrib" > /etc/apt/sources.list run echo "deb-src http://mirrors.aliyun.com/debian/ buster main non-free contrib" >> /etc/apt/sources.list run echo "deb http://mirrors.aliyun.com/debian-security buster/updates main" >> /etc/apt/sources.list run echo "deb-src http://mirrors.aliyun.com/debian-security buster/updates main" >> /etc/apt/sources.list run echo "deb http://mirrors.aliyun.com/debian/ buster-updates main non-free contrib" >> /etc/apt/sources.list run echo "deb-src http://mirrors.aliyun.com/debian/ buster-updates main non-free contrib" >> /etc/apt/sources.list run echo "deb http://mirrors.aliyun.com/debian/ buster-backports main non-free contrib" >> /etc/apt/sources.list run echo "deb-src http://mirrors.aliyun.com/debian/ buster-backports main non-free contrib" >> /etc/apt/sources.list run apt-get update -y run apt-get install -y git lrzsz vim run pip install supervisor -i https://mirrors.aliyun.com/pypi/simple/ run pip install gunicorn -i https://mirrors.aliyun.com/pypi/simple/ run pip install gevent -i https://mirrors.aliyun.com/pypi/simple/ run /usr/local/bin/echo_supervisord_conf > /etc/supervisord.conf run echo "[include]">>/etc/supervisord.conf run echo "files = /etc/supervisor/*.ini">>/etc/supervisord.conf add sy.ini /etc/supervisor/sy.ini add sy_evaluatejkapi /root/projects/sy_evaluatejkapi run pip3 install -r /root/projects/sy_evaluatejkapi/requirements.txt -i https://mirrors.aliyun.com/pypi/simple/ expose 8800 cmd ["supervisord","-c","/etc/supervisord.conf"]
使用docker build -t system:test . 命令构建容器镜像没有异常,但是使用docker run -itd system:test运行容器就会显示容器不在运行。
解决方式:
把cmd ["supervisord","-c","/etc/supervisord.conf"]命令改成cmd ["supervisord","-n","-c","/etc/supervisord.conf"]就可以成功运行了。
supervisor里是这么写的-n/--nodaemon -- run in the foreground (same as 'nodaemon=true' in config file),加了-n让supervisor在前台保持运行就可以了。
以上这篇supervisor下的dockerfile的多服务镜像封装操作就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
下一篇: mac系统怎么获取最好权限删除顽固文件?