2015-01-26 wcdj
摘要:创建nginx镜像与上文《使用Dockerfile搭建Apache Web服务器》类似。
编译Nginx镜像的Dockerfile见GitHub的源码。
root@gerryyang:~/nginx_ubuntu# docker ps a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3fa70f39af75 ubuntu_sshd_gcc_nginx_gerry:14.04 "/run.sh" About an hour ago Up About an hour 0.0.0.0:30022->22/tcp, 0.0.0.0:30080->80/tcp, 0.0.0.0:30443->443/tcp distracted_wilson
101bc295b601 ubuntu_sshd_gcc_apache_gerry:14.04 "/run.sh" About an hour ago Up About an hour 0.0.0.0:20022->22/tcp, 0.0.0.0:20080->80/tcp suspicious_sinoussi
cec21c3c0a1f registry:latest "docker-registry" About an hour ago Up About an hour 0.0.0.0:5000->5000/tcp boring_torvalds
6906a758711c ubuntu_sshd_gcc_gerry:14.04 "/run.sh" About an hour ago Up About an hour 0.0.0.0:10022->22/tcp determined_kirch
root@gerryyang:~# docker exec -it 3fa /bin/bash
root@3fa70f39af75:/etc/nginx# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.1 17956 1408 ? Ss 23:04 0:00 /bin/bash /run.sh
root 8 0.0 0.4 85868 4088 ? S 23:04 0:00 nginx: master process /usr/sbin/nginx
root 9 0.0 0.1 61364 1192 ? Ss 23:04 0:00 /usr/sbin/sshd
www-data 10 0.0 0.2 86212 2276 ? S 23:04 0:00 nginx: worker process
www-data 11 0.0 0.1 86212 2020 ? S 23:04 0:00 nginx: worker process
www-data 12 0.0 0.1 86212 2020 ? S 23:04 0:00 nginx: worker process
www-data 13 0.0 0.1 86212 1764 ? S 23:04 0:00 nginx: worker process
root 14 0.1 0.1 18144 1868 ? S 23:56 0:00 /bin/bash
root 30 0.0 0.1 15568 1140 ? R+ 23:56 0:00 ps aux
root@3fa70f39af75:/etc/nginx# netstat -aunpt
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
tcp6 0 0 :::80 :::* LISTEN -
tcp6 0 0 :::22 :::* LISTEN -
1,运行Nginx的容器,为了充分发挥Nginx的性能,需要对系统内核参数做一些调整。
2,容器运行后,进入容器的方法有两种,一种是在宿主主机通过 docker exec -it $containerid /bin/bash 的方法,另一种方式是通过ssh远程登陆。