1。[uniview-sc@uniview-sc ~]$ sudo systemctl status docker #检查docker服务是否运行
● docker.service - Docker Application Container EngineLoaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor pres
Active: active (running) since Sun 2017-04-09 15:02:01 CST; 13s ago
2.[uniview-sc@uniview-sc ~]$ sudo systemctl enable docker #设置docker为开机自启动
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.
3.[uniview-sc@uniview-sc ~]$ sudo docker pull hub.c.163.com/public/nginx:1.2.1 #从163蜂巢上拉取nginx镜像。注意此处仅仅实验。实际上并不使用此镜像,而是在一个centos7.2干净的镜像上,新装nginx等
Status: Downloaded newer image for hub.c.163.com/public/nginx:1.2.1
4.[uniview-sc@uniview-sc ~]$ sudo docker images
[sudo] uniview-sc 的密码:REPOSITORY TAG IMAGE ID CREATED SIZE
hub.c.163.com/public/centos 7.2.1511 84352c4ff678 6 months ago 356MB
hub.c.163.com/public/nginx 1.2.1 2dc68ff797db 11 months ago 172MB
hub.c.163.com/public/centos latest 997f0ed97903 13 months ago 442MB
5。拉取centos7.2 的docker镜像,并且启动docker容器,进入bash shell命令行
[uniview-sc@uniview-sc ~]$ sudo docker run -t -i --name centos7.2.1511_base 84352c4ff678 /bin/bash #红色字体为docker image id[root@1eda9217c25f /]# ifconfig #此处在docker 容器中查看网络设置.
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.3 netmask 255.255.0.0 broadcast 0.0.0.0
ether 02:42:ac:11:00:03 txqueuelen 0 (Ethernet)
RX packets 7 bytes 586 (586.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@1eda9217c25f /]# ping www.baidu.com
PING www.a.shifen.com (115.239.210.27) 56(84) bytes of data.
64 bytes from 115.239.210.27: icmp_seq=1 ttl=55 time=6.08 ms
64 bytes from 115.239.210.27: icmp_seq=2 ttl=55 time=8.63 ms
^C64 bytes from 115.239.210.27: icmp_seq=3 ttl=55 time=4.14 ms
6.安装epel-release,nginx
[root@1eda9217c25f /]# yum install epel-releaseInstalled:
epel-release.noarch 0:7-9
[root@1eda9217c25f /]# yum install nginx
Complete!
7.安装python-devel , python-pip,后面我们要在docker中安装uwsgi,django
[root@1eda9217c25f /]# yum install python-devel python python-pip
Installed:python-devel.x86_64 0:2.7.5-48.el7 python2-pip.noarch 0:8.1.2-5.el7
8.首先升级pip,再通过pip 安装 uwsgi
[root@1eda9217c25f /]# pip install --upgrade pip
[root@1eda9217c25f /]# pip install uwsgi
Successfully installed pip-9.0.19.为docker中的centos安装bash-completion
[root@1eda9217c25f /]# yum install python-devel python python-pip bash-completion
Installed:bash-completion.noarch 1:2.1-6.el7
10.启动nginx
[root@1eda9217c25f /]# nginx
11.设置nginx开机自启动。
[root@1eda9217c25f /]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
12.在容器内部的centos下面通过curl访问本地80端口(web服务器)。检查nginx是否工作正常?
[root@1eda9217c25f /]# curl http://127.0.0.1 #如下内容有省略.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Test Page for the Nginx HTTP Server on Fedora</title>
</head>
<body>
<h1>Welcome to <strong>nginx</strong> on Fedora!</h1>
</html>
[root@1eda9217c25f /]# ifconfig # docker容器系统的ip地址.
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.3 netmask 255.255.0.0 broadcast 0.0.0.0
ether 02:42:ac:11:00:03 txqueuelen 0 (Ethernet)
RX packets 24146 bytes 35675699 (34.0 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 11641 bytes 793510 (774.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
13.简单起见,在宿机中关闭防火墙。访问docker中的nginx欢迎页面。
[uniview-sc@uniview-sc ~]$ sudo systemctl disable iptables #设置iptables防火墙开机不启动.
[uniview-sc@uniview-sc ~]$ systemctl stop iptables #关闭防火墙
[uniview-sc@uniview-sc ~]$ systemctl status iptables
● iptables.service - Packet Filtering Framework
Loaded: loaded (/usr/lib/systemd/system/iptables.service; disabled; vendor preset: disabled)
Active: inactive (dead)
14.在宿机中通过curl访问docker中的nginx网站测试页面。
[uniview-sc@uniview-sc ~]$ curl http://172.17.0.3
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Test Page for the Nginx HTTP Server on Fedora</title>
</head>
<body>
<h1>Welcome to <strong>nginx</strong> on Fedora!</h1>
</body>
</html>