标签:containe tar art rom too main arch chm pms
支持ssh+nginx+进程自启的dockerfile--------Dockerfile 1 -------------------------------------------------------------------------------------------
在同一目录下编写Dokerfile文件,以及提前copy authorized_keys 文件,支持ssh验证,yum源如果下载不了自己配置源
vim Dockerfile
FROM centos:latest
MAINTAINER xiaoxue xiaoxuenice@qq.com
run rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
RUN yum install -y nginx openssh-server sudo net-tools
RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
RUN ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key
RUN ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key
ADD authorized_keys /root/.ssh/authorized_keys
#同一目录下提前放置authorized_keys文件
RUN echo -e "#!/bin/sh \n/usr/sbin/sshd \n /usr/sbin/nginx -g ‘daemon off;‘ " > /a.sh
#在配置entrypoint时候,最后一个进程要后台运行,也就是守护进程关闭,如果sshd在最后加-D
run chmod +x /a.sh
EXPOSE 80 22
#CMD ["/usr/sbin/nginx","-g","daemon off;"]
ENTRYPOINT ["/a.sh"]
然后你就执行下面两行
docker build -t nginx:1.1 .
docker run --name container1 -dit -p8080:80 -p2222:22 nginx:1.1
docker restart container1
试试容器重启是不是nginx开启,ssh可以连接了,ok。。。
-----------Dockerfile 2------------------------------------------------------------------------------------------
在同一目录下编写Dokerfile文件,以及提前copy authorized_keys 文件,支持ssh验证
vim Dockerfile
FROM centos:latest
MAINTAINER xiaoxue xiaoxuenice@qq.com
run rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
RUN yum install -y nginx openssh-server sudo net-tools
RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
RUN ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key
RUN ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key
#同一目录下提前放置authorized_keys文件
ADD authorized_keys /root/.ssh/authorized_keys
RUN echo -e "#!/bin/sh \nsystemctl enable nginx \nsystemctl enable sshd " > /a.sh
run chmod +x /a.sh
run sh /a.sh
EXPOSE 80
#ENTRYPOINT ["/usr/sbin/nginx","-g","daemon off;"]
CMD ["init"]
然后你就执行下面两行
docker build -t nginx:1.2 .
docker run --name container2 --privileged -dit -p222:22 -p880:80 nginx:1.2 init
docker restart container2
试试容器重启是不是nginx开启,ssh可以连接了,ok。。。
###########(cmd/entrypoit,区别在于cmd会被run指定命令覆盖)##########
Dockerfile编写 支持systemctl ,支持ssh ,支持nginx,(容器自启进程)
标签:containe tar art rom too main arch chm pms
原文地址:https://blog.51cto.com/982439641/2418750