最近实验室的学弟学妹们要展示自己的静态网站作业,想着自己阿里云上还有一台服务器,就准备用docke 给他们做一个展示。参考了一部分dockerfile但是仍然不太好 FROM alpine:latest MAINTAINER becivells <becivells@gmail.com> RUN apk add --update openssh RUN apk add nginx RUN ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa RUN sed -i "s/UsePrivilegeSeparation.*/UsePrivilegeSeparation no/g" /etc/ssh/sshd_config && sed -i "s/UsePAM.*/UsePAM no/g" /etc/ssh/sshd_config && sed -i "s/PermitRootLogin.*/PermitRootLogin yes/g" /etc/ssh/sshd_config && sed -i "s/#AuthorizedKeysFile/AuthorizedKeysFile/g" /etc/ssh/sshd_config EXPOSE 80 EXPOSE 22 CMD ["nginx", "-g", "daemon off;"] CMD ["/usr/sbin/sshd","-D"] 建立Docker 镜像dockerfile要和执行命令的在一个路径下 docker build -t alpine:nginx_ssh . alpine Linux 确实小。而且管理方便。但是软件源少,也缺少一些管理命令需要手动安装 apk --update add 软件名#更新并且下载软件 例如 apk --update add openssh #我参照官网上配置ssh,结果ssh死活不能用 apk search 软件名 #搜索软件 觉得其他的和其他linux 基本上都一样 建立以后运行 docker run -i -t -p 80:80 -p 2333:22 alpine:nginx_ssh sh 下一条只做参考 docker run -i -t -p 80:80 -p 2333:22 -v /docker/alpine/nginx:/var/lib/nginx/html alpine:nginx_ssh sh 2016-11-5改进了一下,用证书登录,当然也可以用密码登陆 FROM alpine:latest MAINTAINER becivells <becivells@gmail.com> RUN apk add --update openssh RUN apk add nginx RUN ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa &&\ ssh-keygen -f /etc/ssh/ssh_host_dsa_key -N '' -t dsa &&\ ssh-keygen -f /etc/ssh/ssh_host_ecdsa_key -N '' -t ecdsa &&\ ssh-keygen -f /etc/ssh/ssh_host_ed25519_key -N '' -t ed25519 RUN sed -i "s/UsePrivilegeSeparation.*/UsePrivilegeSeparation no/g" /etc/ssh/sshd_config && sed -i "s/UsePAM.*/UsePAM no/g" /etc/ssh/sshd_config && sed -i "s/PermitRootLogin.*/PermitRootLogin yes/g" /etc/ssh/sshd_config && sed -i "s/#AuthorizedKeysFile/AuthorizedKeysFile/g" /etc/ssh/sshd_config RUN adduser -D www &&\ mkdir -p /home/www/.ssh &&\ mkdir -p /run/nginx/ &&\ mkdir -p /home/www/html &&\ ln -s /home/www/html/ /var/www/ && \ echo "www:123456" | chpasswd COPY nginx.conf /etc/nginx/nginx.conf RUN chown www:www -R /home/www/ &&\ chmod 755 -R /home/www/ &&\ echo "nginx" >>/etc/start.sh &&\ echo "/usr/sbin/sshd -D" >>/etc/start.sh EXPOSE 80 EXPOSE 22 CMD ["/bin/sh","/etc/start.sh"] nginx.conf worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; autoindex on; autoindex_exact_size on; autoindex_localtime on; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location / { root /var/www/; } } } 运行 docker run -d -p 80:80 -p 23333:22 -v /主机目录/:/var/www nginx 可以拉取docker pull becivells/nginxssh 可以写个脚本批量开启参考https://hub.docker.com/r/danielguerra/alpine-sshd/~/dockerfile/ (责任编辑:IT) |