Docker系列(一)安装部署

时间:2022-01-24 21:49:20

1.1 环境说明

[root@localhost ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
--2017-10-24 23:31:32-- http://mirrors.aliyun.com/repo/epel-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 36.250.235.85, 36.250.235.84, 36.250.235.101, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)
|36.250.235.85|:80... connected.
HTTP request sent, awaiting response...
200 OK
Length:
1084 (1.1K) [application/octet-stream]
Saving to: ‘
/etc/yum.repos.d/epel.repo’

100%[=================================================================================================>] 1,084 --.-K/s in 0s

2017-10-24 23:31:32 (43.0 MB/s) - ‘/etc/yum.repos.d/epel.repo’ saved [1084/1084]

[root@localhost
~]# cat /etc/redhat-release
CentOS Linux release
7.2.1511 (Core)
[root@localhost
~]# uname -a
Linux localhost.localdomain
3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost
~]# hostname -I
10.0.0.30

1.2 下载docker
centos7可以直接yum安装docker

[root@localhost ~]# yum install -y docker 
Loaded plugins: fastestmirror
http:
//mirrors.aliyuncs.com/epel/7/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
Trying other mirror.
epel
| 4.3 kB 00:00:00
(
1/3): epel/x86_64/group_gz | 170 kB 00:00:00
(
2/3): epel/x86_64/updateinfo | 841 kB 00:00:01
(
3/3): epel/x86_64/primary_db | 4.8 MB 00:00:06
Loading mirror speeds from cached hostfile
* base: mirrors.btte.net
* epel: mirrors.aliyun.com
* extras: mirrors.btte.net
* updates: mirrors.btte.net
Resolving Dependencies
--> Running transaction check
---> Package docker.x86_64 2:1.12.6-55.gitc4618fb.el7.centos will be installed
--> Processing Dependency: docker-common = 2:1.12.6-55.gitc4618fb.el7.centos for package: 2:docker-1.12.6-55.gitc4618fb.el7.centos.x86_64
--> Processing Dependency: docker-client = 2:1.12.6-55.gitc4618fb.el7.centos for package: 2:docker-1.12.6-55.gitc4618fb.el7.centos.x86_64
--> Processing Dependency: libseccomp.so.2()(64bit) for

1.3 查看下载版本

[root@localhost ~]# docker version
Client:
Version:
1.12.6
API version:
1.24
Package version: docker
-1.12.6-55.gitc4618fb.el7.centos.x86_64
Go version: go1.
8.3
Git commit: c4618fb
/1.12.6
Built: Thu Sep
21 22:33:52 2017
OS
/Arch: linux/amd64
Cannot connect to the Docker daemon. Is the docker daemon running on this host
?

1.4 启动docker并加入开机自启动项

[root@localhost ~]# systemctl start docker
[root@localhost
~]# systemctl enable docker
Created symlink from
/etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@localhost
~]# systemctl status docker
● docker.service
- Docker Application Container Engine
Loaded: loaded (
/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: active (running) since Tue
2017-10-24 23:37:13 CST; 24s ago
Docs: http:
//docs.docker.com
Main PID: 5368 (dockerd-current)
CGroup:
/system.slice/docker.service
├─
5368 /usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-ru...
└─
5375 /usr/bin/docker-containerd-current -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --shim docker-contai...

Oct
24 23:37:12 localhost.localdomain dockerd-current[5368]: time="2017-10-24T23:37:12.689193360+08:00" level=info msg="Graph migra...onds"
Oct
24 23:37:12 localhost.localdomain dockerd-current[5368]: time="2017-10-24T23:37:12.690265739+08:00" level=warning msg="mountpoi...ound"
Oct
24 23:37:12 localhost.localdomain dockerd-current[5368]: time="2017-10-24T23:37:12.690637517+08:00" level=info msg="Loading con...art."
Oct
24 23:37:12 localhost.localdomain dockerd-current[5368]: time="2017-10-24T23:37:12.704449384+08:00" level=info msg="Firewalld r...true"
Oct
24 23:37:12 localhost.localdomain dockerd-current[5368]: time="2017-10-24T23:37:12.856871891+08:00" level=info msg="Default bri...ress"
Oct
24 23:37:13 localhost.localdomain dockerd-current[5368]: time="2017-10-24T23:37:13.061454864+08:00" level=info msg="Loading con...one."
Oct
24 23:37:13 localhost.localdomain dockerd-current[5368]: time="2017-10-24T23:37:13.061648836+08:00" level=info msg="Daemon has ...tion"
Oct
24 23:37:13 localhost.localdomain dockerd-current[5368]: time="2017-10-24T23:37:13.061681015+08:00" level=info msg="Docker daem....12.6
Oct 24 23:37:13 localhost.localdomain dockerd-current[5368]: time="2017-10-24T23:37:13.065980762+08:00" level=info msg="API listen ...sock"
Oct
24 23:37:13 localhost.localdomain systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use
-l to show in full.
[root@localhost
~]# docker version
Client:
Version:
1.12.6
API version:
1.24
Package version: docker
-1.12.6-55.gitc4618fb.el7.centos.x86_64
Go version: go1.
8.3
Git commit: c4618fb
/1.12.6
Built: Thu Sep
21 22:33:52 2017
OS
/Arch: linux/amd64

Server:
Version:
1.12.6
API version:
1.24
Package version: docker
-1.12.6-55.gitc4618fb.el7.centos.x86_64
Go version: go1.
8.3
Git commit: c4618fb
/1.12.6
Built: Thu Sep
21 22:33:52 2017
OS
/Arch: linux/amd64

1.5 测试验证

[root@localhost ~]# docker run hello-world
Unable to
find image 'hello-world:latest' locally
Trying to pull repository docker.io
/library/hello-world ...
latest: Pulling from docker.io
/library/hello-world
5b0f327be733: Pull complete
Digest: sha256:07d5f7800dfe37b8c2196c7b1c524c33808ce2e0f74e7aa00e603295ca9a0972

Hello from Docker
!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.

To try something
more ambitious, you can run an Ubuntu container with:
$ docker run
-it ubuntu bash

Share images, automate workflows, and
more with a free Docker ID:
https:
//cloud.docker.com/

For
more examples and ideas, visit:
https:
//docs.docker.com/engine/userguide/

由于本地没有hello-world这个镜像,所以会下载一个hello-world的镜像,并在容器内运行
1.6 网卡信息

[root@localhost ~]# ifconfig
docker0: flags
=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet
172.17.0.1 netmask 255.255.0.0 broadcast 0.0.0.0
inet6 fe80::
42:56ff:fe36:3c46 prefixlen 64 scopeid 0x20<link>
ether
02:42:56:36:3c:46 txqueuelen 0 (Ethernet)
RX packets
1 bytes 76 (76.0 B)
RX errors
0 dropped 0 overruns 0 frame 0
TX packets
2 bytes 180 (180.0 B)
TX errors
0 dropped 0 overruns 0 carrier 0 collisions 0

eth0: flags
=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet
10.0.0.30 netmask 255.255.255.0 broadcast 10.0.0.255
inet6 fe80::20c:29ff:fe8e:7ec2 prefixlen
64 scopeid 0x20<link>
ether
00:0c:29:8e:7e:c2 txqueuelen 1000 (Ethernet)
RX packets
32141 bytes 46613749 (44.4 MiB)
RX errors
0 dropped 0 overruns 0 frame 0
TX packets
11010 bytes 921935 (900.3 KiB)
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
inet6 ::
1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen
0 (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