#新生成的镜像是基于sshd:dockerfile镜像FROM sshd-centos
MAINTAINER by cmzsteven
WORKDIR /usr/local/src
#安装wget
RUN yum install -y wget
#下载并解压源码包
RUN wget
RUN tar -zxvf nginx-1.8.0.tar.gz
WORKDIR nginx-1.8.0
#编译安装nginx
RUN yum install -y gcc make pcre-devel zlib-devel
RUN ./configure --prefix=/usr/local/nginx --with-pcre
RUN make
RUN make install
#启动Nginx服务
RUN /usr/local/nginx/sbin/nginx
#修改Nginx配置文件,以非daemon方式启动
RUN echo "daemon off;">>/usr/local/nginx/conf/nginx.conf
#复制服务启动脚本并设置权限
ADD run.sh /usr/local/sbin/run.sh
RUN chmod 755 /usr/local/sbin/run.sh
#设置生成容器时需要执行的脚本
CMD ["/usr/local/sbin/run.sh"]
#开放22、80、443端口
EXPOSE 22
EXPOSE 80
EXPOSE 443
[[email protected] nginx_centos]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c69d42541f52 nginx_dockerfile:centos "/usr/local/sbin/run 26 seconds ago Up 25 seconds 0.0.0.0:2224->22/tcp, 0.0.0.0:8001->80/tcp, 0.0.0.0:4443->443/tcp high_colden
f5a87e085a0b nginx:centos "/usr/local/sbin/run 49 minutes ago Up 49 minutes 0.0.0.0:2223->22/tcp, 0.0.0.0:8000->80/tcp stoic_kirch
ed9361b598c8 sshd-centos "/usr/sbin/sshd -D" About an hour ago Up About an hour 0.0.0.0:2222->22/tcp distracted_mclean
3、测试 测试nignx:
[[email protected] nginx_centos]# curl localhost:8001
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body { width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }</style></head><body><h1>Welcome to nginx!</h1><p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p><p>For online documentation and support please refer to<a href="http://nginx.org/">nginx.org</a>.<br/>Commercial support is available at<a href="http://nginx.com/">nginx.com</a>.</p><p><em>Thank you for using nginx.</em></p></body></html>12345678910111213141516171819202122232425261234567891011121314151617181920212223242526
测试成功!
测试ssh
[[email protected] nginx_centos]# ssh localhost -p 2224
The authenticity of host '[localhost]:2224 ([::1]:2224)' can't be established.RSA key fingerprint is d7:fd:3d:40:46:b6:0c:c9:ee:f1:fb:9e:08:c4:12:57.Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[localhost]:2224' (RSA) to the list of known [email protected]'s password:12345671234567