With me step by step deployment docker container Author: Zhang Yanfeng, please indicate the source pseudonym: clouds dreams
table of Contents:
1. Basic environmental inspection
2. Install epel source
3. Install the official Docker source
4. Install the latest version of Docker and configure
5. Start Docker
6. Check docker configuration and startup
7. Start the first Docker container
1. Basic environmental inspection
#Check environment
[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-1127.el7.x86_64 #1 SMP Tue Mar 31 23:36:51 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.8.2003 (Core)
#Turn off the firewall and SELinux
setenforce 0
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
systemctl stop firewalld
systemctl disable firewalld
#Check network
[root@localhost ~]# ping www.baidu.com -c 2
PING www.a.shifen.com (110.242.68.3) 56(84) bytes of data.
64 bytes from 110.242.68.3 (110.242.68.3): icmp_seq=1 ttl=52 time=24.2 ms
64 bytes from 110.242.68.3 (110.242.68.3): icmp_seq=2 ttl=52 time=27.3 ms
#Check memory
[root@localhost ~]# free -m
total used free shared buff/cache available
Mem: 981 231 102 7 647 595
Swap: 2047 0 2047
2. Install epel source
Install epel source
yum -y install wget
cd /etc/yum.repos.d/
wget http://mirrors.aliyun.com/repo/epel-7.repo
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
yum clean all
yum makecache
yum -y install lrzsz net-tools epel-release
Here you can see that there is also docker1.13.1 in the epel source
[root@localhost ~]# yum list docker --show-duplicates
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
Loading mirror speeds from cached hostfile
* c7-media:
Available Packages
docker.x86_64 2:1.13.1-102.git7f2769b.el7.centos extras
3. Install the official Docker source
Install the docker-ce source:
[root@localhost ~]# yum install yum-utils -y
[root@localhost ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Here you can see the docker image in the docker-ce source
[root@localhost ~]# yum list docker-ce --show-duplicates
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
Loading mirror speeds from cached hostfile
* c7-media:
Available Packages
docker-ce.x86_64 3:19.03.15-3.el7 docker-ce-stable
docker-ce.x86_64 3:20.10.5-3.el7 docker-ce-stable
4. Install the latest version of Docker and configure
[root@localhost ~]# yum -y install docker-ce
[root@localhost ~]# mkdir /etc/docker
[root@localhost ~]# cd /etc/docker/
[root@localhost docker]# vi /etc/docker/daemon.json
{
"graph": "/data/docker",
"storage-driver": "overlay2",
"insecure-registries": ["registry.access.redhat.com","quay.io"],
"registry-mirrors": ["https://q2gr04ke.mirror.aliyuncs.com"],
"bip": "172.43.101.1/24",
"exec-opts": ["native.cgroupdriver=systemd"],
"live-restore": true
}
Content description:
{
"graph": "/data/docker", #docker working directory
"storage-driver": "overlay2", #Storage driver
"insecure-registries": ["registry.access.redhat.com","quay.io"], # Insecure warehouse
"registry-mirrors": ["https://q2gr04ke.mirror.aliyuncs.com"], # Speed up mirroring
"bip": "172.43.101.1/24", #docker's network, try to have a contrast relationship with the host
"exec-opts": ["native.cgroupdriver=systemd"], #cgroup的类型
"live-restore": true #Let the docker container not rely on the death and life of the docker engine
}
5. Start Docker
[root@localhost ~]# systemctl enable docker.service
[root@localhost ~]# systemctl start docker.service
[root@localhost ~]# docker version
Client: Docker Engine - Community
Version: 20.10.5
API version: 1.41
Go version: go1.13.15
Git commit: 55c4c88
Built: Tue Mar 2 20:33:55 2021
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.5
API version: 1.41 (minimum version 1.12)
Go version: go1.13.15
Git commit: 363e9a8
Built: Tue Mar 2 20:32:17 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.4
GitCommit: 05f951a3781f4f2c1911b05e61c160e9c30eaa8e
runc:
Version: 1.0.0-rc93
GitCommit: 12644e614e25b05da6fd08a38ffa0cfe1903fdec
docker-init:
Version: 0.19.0
GitCommit: de40ad0
6. Check docker configuration and startup
[root@localhost ~]# docker info
Client:
Context: default
Debug Mode: false
Plugins:
app: Docker App (Docker Inc., v0.9.1-beta3)
buildx: Build with BuildKit (Docker Inc., v0.5.1-docker)
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 20.10.5 #Docker version
Storage Driver: overlay2 #Storage Driver
Backing Filesystem: xfs #File system
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: systemd
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 05f951a3781f4f2c1911b05e61c160e9c30eaa8e
runc version: 12644e614e25b05da6fd08a38ffa0cfe1903fdec
init version: de40ad0
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-1127.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 981.9MiB
Name: localhost.localdomain
ID: 6WQE:UXYL:LED5:IJM5:FEV4:CEHF:DFLP:VFIE:O262:PK3Y:TADB:AD7H
Docker Root Dir: /data/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
registry.access.redhat.com
quay.io
127.0.0.0/8
Registry Mirrors:
https://q2gr04ke.mirror.aliyuncs.com/
Live Restore Enabled: true
7. Start the first Docker container
[root@localhost ~]# docker run hello-world
Unable to find image'hello-world:latest' locally #<==Cannot find a container called hello-world locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:31b9c7d48790f0d8c50ab433d9c3b7e17666d6993084c002c2ff1ca09b96391d #<==Analyze whether MD5 is correct
Status: Downloaded newer image for hello-world:latest #<==The download is complete, and a latest hello-world:latest image is downloaded.
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/
Explain the above four steps:
1. The client is connected to the server
2. The server found that there was no hello-world mirror locally, and then pulled it from github.
3. Then use this image as a template to get this hello-world container up.
4. The Docker daemon transfers the output to the Docker client, and then sends it to your terminal.