CentOS7 部署docker

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
1.docker安装
CentOS7 
yum  install  epel-release -y
yum  install  docker -y
 
[[email protected] ~] # docker version
Client:
  Version:         1.12.6
  API version:     1.24
  Package version: docker-1.12.6-61.git85d7426.el7.centos.x86_64
  Go version:      go1.8.3
  Git commit:      85d7426 /1 .12.6
  Built:           Tue Oct 24 15:40:21 2017
  OS /Arch :         linux /amd64
 
Server:
  Version:         1.12.6
  API version:     1.24
  Package version: docker-1.12.6-61.git85d7426.el7.centos.x86_64
  Go version:      go1.8.3
  Git commit:      85d7426 /1 .12.6
  Built:           Tue Oct 24 15:40:21 2017
  OS /Arch :         linux /amd64
 
[[email protected] ~] # docker info
Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
Images: 0
Server Version: 1.12.6
Storage Driver: devicemapper
  Pool Name: docker-253:0-270443527-pool
  Pool Blocksize: 65.54 kB
  Base Device Size: 10.74 GB
  Backing Filesystem: xfs
  Data  file /dev/loop0
  Metadata  file /dev/loop1
  Data Space Used: 11.8 MB
  Data Space Total: 107.4 GB
  Data Space Available: 102.8 GB
  Metadata Space Used: 581.6 kB
  Metadata Space Total: 2.147 GB
  Metadata Space Available: 2.147 GB
  Thin Pool Minimum Free Space: 10.74 GB
  Udev Sync Supported:  true
  Deferred Removal Enabled:  true
  Deferred Deletion Enabled:  true
  Deferred Deleted Device Count: 0
  Data loop  file /var/lib/docker/devicemapper/devicemapper/data
  WARNING: Usage of loopback devices is strongly discouraged  for  production use. Use `--storage-opt dm.thinpooldev` to specify a custom block storage device.
  Metadata loop  file /var/lib/docker/devicemapper/devicemapper/metadata
  Library Version: 1.02.107-RHEL7 (2015-10-14)
Logging Driver: journald
Cgroup Driver: systemd
Plugins:
  Volume:  local
  Network: host bridge overlay null
Swarm: inactive
Runtimes: docker-runc runc
Default Runtime: docker-runc
Security Options: seccomp
Kernel Version: 3.10.0-327.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
Number of Docker Hooks: 3
CPUs: 2
Total Memory: 1.954 GiB
Name: localhost.localdomain
ID: 7NNL:RVYC:M6QY:CP2P:5SNV:3N25:U45I:TUWG:Y4NK:7H4R:CN2B:3E67
Docker Root Dir:  /var/lib/docker
Debug Mode (client):  false
Debug Mode (server):  false
Registry: https: //index .docker.io /v1/
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
Insecure Registries:
  127.0.0.0 /8
Registries: docker.io (secure)
 
 
CentOS6 
yum  install  epel-release -y
yum  install  lxc libcgroup device-map* -y
yum  install  docker-io -y
 
[[email protected] ~] # docker version
Client version: 1.7.1
Client API version: 1.19
Go version (client): go1.4.2
Git commit (client): 786b29d /1 .7.1
OS /Arch  (client): linux /amd64
Server version: 1.7.1
Server API version: 1.19
Go version (server): go1.4.2
Git commit (server): 786b29d /1 .7.1
OS /Arch  (server): linux /amd64
 
[[email protected] ~] # docker info
Containers: 0
Images: 0
Storage Driver: devicemapper
  Pool Name: docker-253:0-130626-pool
  Pool Blocksize: 65.54 kB
  Backing Filesystem: extfs
  Data  file /dev/loop0
  Metadata  file /dev/loop1
  Data Space Used: 305.7 MB
  Data Space Total: 107.4 GB
  Data Space Available: 11.1 GB
  Metadata Space Used: 729.1 kB
  Metadata Space Total: 2.147 GB
  Metadata Space Available: 2.147 GB
  Udev Sync Supported:  true
  Deferred Removal Enabled:  false
  Data loop  file /var/lib/docker/devicemapper/devicemapper/data
  Metadata loop  file /var/lib/docker/devicemapper/devicemapper/metadata
  Library Version: 1.02.117-RHEL6 (2016-12-13)
Execution Driver: native-0.2
Logging Driver: json- file
Kernel Version: 2.6.32-431.el6.x86_64
Operating System: <unknown>
CPUs: 1
Total Memory: 1.834 GiB
Name: localhost.localdomain
ID: SKZZ:TYST:LUEG:N66O:364P:7YRG:GQ3W:ODYR:G476:JSHB:I2HF:3A5W
 
说明:docker 默认的存储驱动类型为devicemapper,docker-ce 默认的存储驱动类型为overlay2。
 
2.搜索并下载nginx容器
[[email protected] ~] # docker search nginx
[[email protected] ~] # docker pull docker.io/nginx
 
3.将容器的80端映射到本机的8080
[[email protected] ~] # docker run --name=nginx -itd -p8080:80 docker.io/nginx bash
或者
[[email protected] ~] # docker run --name nginx -itd -p8080:80 docker.io/nginx /bin/bash  
或者
[[email protected] ~] # docker run --name=nginx -itd -p8080:80 docker.io/nginx
 
注:--privileged 给予管理员权限,--restart=always 容器随docker宿主机的启动而启动;CentOS7安装服务器后若使用systemctl工具启动创建容器时需要执行 /usr/sbin/init /sbin/init 命令。
 
4.查看docker容器进程
[[email protected] ~] # docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                  NAMES
26ae21c8bddd        docker.io /nginx      "bash"               5 seconds ago       Up 4 seconds        0.0.0.0:8080->80 /tcp    nginx
 
5.查看docker容器IP地址
[[email protected] ~] # docker inspect 0a9db4be695b |grep -i ip
                         "HostIp" "" ,
             "IpcMode" "" ,
             "LinkLocalIPv6Address" "" ,
             "LinkLocalIPv6PrefixLen" : 0,
                         "HostIp" "0.0.0.0" ,
             "SecondaryIPAddresses" : null,
             "SecondaryIPv6Addresses" : null,
             "GlobalIPv6Address" "" ,
             "GlobalIPv6PrefixLen" : 0,
             "IPAddress" "172.17.0.2" ,
             "IPPrefixLen" : 16,
             "IPv6Gateway" "" ,
                     "IPAMConfig" : null,
                     "IPAddress" "172.17.0.2" ,
                     "IPPrefixLen" : 16,
                     "IPv6Gateway" "" ,
                     "GlobalIPv6Address" "" ,
                     "GlobalIPv6PrefixLen" : 0,
 
6.浏览器访问测试:
http: //IP :8080

1.png

1
2
3
4
5
6
7
8
9
10
11
12
7.登录进入容器中,更改默认的测试页面内容
[[email protected] ~] # docker exec -it 0a9db4be695b /bin/bash
[email protected]:/ # cd /usr/share/nginx/html/
[email protected]: /usr/share/nginx/html # ls
50x.html  index.html
[email protected]: /usr/share/nginx/html # echo "<h1>www.hello.com</h1>"> index.html 
[email protected]: /usr/share/nginx/html # exit
exit
 
8.浏览器访问测试:
http: //IP :8080

2.png

1
2
9.强制删除所有的虚拟机
[[email protected] ~] # docker rm -f `docker ps -aq`




本文转自 dengaosky 51CTO博客,原文链接:http://blog.51cto.com/dengaosky/2045168,如需转载请自行联系原作者