Introduction
Docker is an open source product of dotcloud, which mainly provides services for developers based on the PAAS platform. It is a container virtualization software that solves the operating environment and configuration problems, facilitates continuous integration and contributes to the overall release.
Docker components
-
Docker warehouse: https://hub.docker.com
-
Docker Client: Docker client.
-
Docker Server: The main component of the Docker daemon, which accepts user requests sent through the Docker Client and implements route distribution according to the corresponding routing rules.
-
Docker image: Docker image becomes a container after running.
Docker installation
Prerequisites
To install Docker, the official recommendation must require a CentOS7 system. The centos-extras
library must be enabled. By default, this repository is enabled, but if it is disabled, you need to re-enable it. overlay2
It is recommended to use a storage driver.
Uninstall the old version
# 全新的ContOS7精简版,没有安装过docker
[root@localhost ~]# yum remove docker \
> docker-client \
> docker-client-latest \
> docker-common \
> docker-latest \
> docker-latest-logrotate \
> docker-logrotate \
> docker-engine
Loaded plugins: fastestmirror
Repository epel is listed more than once in the configuration
Repository epel-debuginfo is listed more than once in the configuration
Repository epel-source is listed more than once in the configuration
No Match for argument: docker
No Match for argument: docker-client
No Match for argument: docker-client-latest
No Match for argument: docker-common
No Match for argument: docker-latest
No Match for argument: docker-latest-logrotate
No Match for argument: docker-logrotate
No Match for argument: docker-engine
No Packages marked for removal
installation
The official recommendation is to use the warehouse to install docker. This demonstration is officially recommended.
Set up warehouse
[root@localhost ~]# yum install -y yum-utils
# 注意,此仓库为官方提供仓库,国内用户访问网络很坑,这里选择阿里仓库
yum-config-manager \
> --add-repo \
> https://download.docker.com/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
- Ali warehouse
[root@localhost ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror
adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
Install Docker Engine
[root@localhost ~]# yum install docker-ce docker-ce-cli containerd.io
Start Docker
[root@localhost ~]# systemctl start docker
View status
[root@localhost ~]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since Sat 2020-04-11 10:15:26 CST; 15s ago
Docs: https://docs.docker.com
Main PID: 18129 (dockerd)
Tasks: 12
Memory: 46.4M
CGroup: /system.slice/docker.service
└─18129 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Apr 11 10:15:25 localhost.localdomain dockerd[18129]: time="2020-04-11T10:15:25.935145283+08:00" level=info msg="scheme \"unix\" not registered, fallback to default scheme" module=grpc
Apr 11 10:15:25 localhost.localdomain dockerd[18129]: time="2020-04-11T10:15:25.935172947+08:00" level=info msg="ccResolverWrapper: sending update to cc: {[{unix:///run/containerd/containerd.sock 0 <nil>}] <nil>}" module=grpc
Apr 11 10:15:25 localhost.localdomain dockerd[18129]: time="2020-04-11T10:15:25.935193242+08:00" level=info msg="ClientConn switching balancer to \"pick_first\"" module=grpc
Apr 11 10:15:25 localhost.localdomain dockerd[18129]: time="2020-04-11T10:15:25.962339880+08:00" level=info msg="Loading containers: start."
Apr 11 10:15:26 localhost.localdomain dockerd[18129]: time="2020-04-11T10:15:26.230751040+08:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can be used to...rred IP address"
Apr 11 10:15:26 localhost.localdomain dockerd[18129]: time="2020-04-11T10:15:26.329307123+08:00" level=info msg="Loading containers: done."
Apr 11 10:15:26 localhost.localdomain dockerd[18129]: time="2020-04-11T10:15:26.353432378+08:00" level=info msg="Docker daemon" commit=afacb8b graphdriver(s)=overlay2 version=19.03.8
Apr 11 10:15:26 localhost.localdomain dockerd[18129]: time="2020-04-11T10:15:26.353629385+08:00" level=info msg="Daemon has completed initialization"
Apr 11 10:15:26 localhost.localdomain dockerd[18129]: time="2020-04-11T10:15:26.381834522+08:00" level=info msg="API listen on /var/run/docker.sock"
Apr 11 10:15:26 localhost.localdomain systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.
test
View version
[root@localhost ~]# docker version
Client: Docker Engine - Community
Version: 19.03.8
API version: 1.40
Go version: go1.12.17
Git commit: afacb8b
Built: Wed Mar 11 01:27:04 2020
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.8
API version: 1.40 (minimum version 1.12)
Go version: go1.12.17
Git commit: afacb8b
Built: Wed Mar 11 01:25:42 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.2.13
GitCommit: 7ad184331fa3e55e52b890ea95e65ba581ae3429
runc:
Version: 1.0.0-rc10
GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
docker-init:
Version: 0.18.0
GitCommit: fec3683
helloworld
# 执行三次也没有成功, 原因是下载镜像失败
[root@localhost ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get https://registry-1.docker.io/v2/library/hello-world/manifests/latest: Get https://auth.docker.io/token?scope=repository%3Alibrary%2Fhello-world%3Apull&service=registry.docker.io: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).
See 'docker run --help'.
[root@localhost ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pulling fs layer
docker: error pulling image configuration: Get https://production.cloudflare.docker.com/registry-v2/docker/registry/v2/blobs/sha256/fc/fce289e99eb9bca977dae136fbe2a82b6b7d4c372474c9235adc1741675f587e/data?verify=1586574550-P3eY%2BuJ7zYienz1l526gNyOltTI%3D: read tcp 192.168.0.11:43826->104.18.121.25:443: read: connection reset by peer.
See 'docker run --help'.
[root@localhost ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).
See 'docker run --help'.
Configure image acceleration
[root@localhost docker]# vi /etc/docker/daemon.json
{
# 此处可选择自己的阿里镜像加速器,也可用这个。
"registry-mirrors": ["https://e9vsm9qn.mirror.aliyuncs.com"]
}
[root@localhost docker]# systemctl daemon-reload
[root@localhost docker]# systemctl restart docker
阿里镜像加速器地址(需要登录):https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors
Execute helloworld again
[root@localhost docker]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:f9dfddf63636d84ef479d645ab5885156ae030f611a56f3a7ac7f2fdd86d7e4e
Status: Downloaded newer image for hello-world:latest
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.
(amd64)
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://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
Uninstall Docker
- Uninstall the Docker Engine, CLI and Containerd packages:
[root@localhost docker]# yum remove docker-ce docker-ce-cli containerd.io
- Images, containers, volumes, or custom configuration files on the host are not automatically deleted. To delete all images, containers and volumes:
[root@localhost docker]# rm -rf /var/lib/docker