centos7 install Docker

Install Docker

I installed Centos7 in a virtual machine, linux 3.10 kernel, docker official says at least 3.8 or above, and recommends 3.10 or above (linux kernel 3.8 or above is required under ubuntu, the RHEL/Centos kernel has been patched, and the centos6.5 version is fine-this is fine try)

1, log in with the root account, check the kernel version as follows

[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018
x86_64 x86_64 x86_64 GNU/Linux

2, update the yum package to the latest

[root@localhost ~]# yum update
Plugin loaded: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.ustc.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.cn99.com
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
Resolving dependencies
--> checking transaction
---> Package NetworkManager.x86_64.1.1.12.0-6.el7 will be upgraded
---> Package NetworkManager.x86_64.1.1.12.0-10.el7_6 will be updated

(To select confirmation during the period, just enter y)

3, install the required software packages, yum-util provides the yum-config-manager function, and the other two are dependent on the devicemapper driver

[root@localhost ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
Plugin loaded: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.ustc.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.cn99.com
Package device-mapper-persistent-data-0.7.3-3.el7.x86_64 is installed and up to date
Package 7:lvm2-2.02.180-10.el7_6.8.x86_64 is installed and up to date
Resolving dependencies
--> checking transaction
---> Package yum-utils.noarch.0.1.1.31-50.el7 will be installed
--> Processing dependency python-kitchen, which is required by package yum-utils-1.1.31-50.el7.noarch
...
...

4, set yum source (choose one)

#central warehouse
yum-config-manager --add-repo http://download.docker.com/linux/centos/docker-ce.repo

#Ali Warehouse
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@localhost ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Plugin loaded: 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

5, you can view all docker versions in all warehouses, and select a specific version to install

[root@localhost ~]# yum list docker-ce --showduplicates | sort -r
Plugin loaded: fastestmirror
Installable Packages
 * updates: mirrors.cn99.com
Loading mirror speeds from cached hostfile
 * extras: mirrors.aliyun.com
docker-ce.x86_64 3:19.03.2-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.1-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.0-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.8-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.7-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.6-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.5-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.4-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.3-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.2-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.1-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.0-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.3.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.2.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.1.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.0.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 18.03.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.12.1.ce-1.el7.centos docker-ce-stable

6, install Docker, command: yum install docker-ce-version number, I chose docker-ce-18.03.1.ce, as follows

[root@localhost ~]# yum install docker-ce-18.03.1.ce
Plugin loaded: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.ustc.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.cn99.com
Resolving dependencies
--> checking transaction
---> Package docker-ce.x86_64.0.18.03.1.ce-1.el7.centos will be installed

(To select confirmation during the period, just enter y)

7, Start Docker, command: systemctl start docker, and then add startup, as follows

[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 ~]# docker version
Client:
 Version: 18.03.1-ce
 API version: 1.37
 Go version: go1.9.5
 Git commit: 9ee9f40
 Built: Thu Apr 26 07:20:16 2018
 OS/Arch: linux/amd64
 Experimental: false
 Orchestrator: swarm
 
Server:
 Engine:
  Version: 18.03.1-ce
  API version: 1.37 (minimum version 1.12)
  Go version: go1.9.5
  Git commit: 9ee9f40
  Built: Thu Apr 26 07:23:58 2018
  OS/Arch: linux/amd64
  Experimental: false

8, set docker source

#Create /etc/docker directory
mkdir -p /etc/docker
#vi open the configuration file
vi /etc/docker/daemon.json

#Reload configuration file
systemctl daemon-reload
# restart docker
systemctl restart docker

curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io
{<!-- -->
    "registry-mirrors": ["http://f1361db2.m.daocloud.io"]
}
{<!-- -->
    "registry-mirrors": ["https://9wmvctk6.mirror.aliyuncs.com"]
}

pycharm connect docker edit python

docker run -d -p 16215:22 -p 8331:8150 \
--restart=always \
--hostname=fth_backend\
-v /opt/projects/fth_backend/:/usr/src/app \
--name fth_backend fth_backend:0.0.1