Installing Docker and Docker compose in CentOS 7

Environmental inspection

Enter root

All of the following are performed as root
sudo -i

View Linux distribution

[root@localhost ~]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

View kernel version

Docker requires the kernel version of CentOS system to be higher than 3.10

[root@localhost /]# uname -r
3.10.0-123.el7.x86_64

conclusion

The release version is CentOS 7, which meets the requirements of Docker environment. Next, install Docker CE using yum.

be careful:

The kernel of version 3.10 may not run normally the docker of version 18.06.x and above (solution: upgrade the kernel or lower the docker version), and the following error may be reported:

docker: Error response from daemon: OCI runtime create failed: container_linux.go:344: starting container process caused "process_linux.go:293: copying bootstrap data to pipe caused "write init-p: broken pipe"": unknown.

Install Docker

 
# Update to the latest yum package
yum update -y

# Uninstall the old version (if the old version has been installed)
yum remove docker docker-common docker-selinux docker-engine docer-io

# Install required packages
# Yum util provides the yum config manager function, and the other two are device mapper driver dependencies
yum install -y yum-utils device-mapper-persistent-data lvm2

# Set yum source
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

# View all docker versions in all warehouses and select a specific version to install
yum list docker-ce --showduplicates | sort -r

* updates: centos.ustc.edu.cn
Loading mirror speeds from cached hostfile
Loaded plugins: fastestmirror, langpacks

* extras: centos.ustc.edu.cn
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
docker-ce.x86_64 17.12.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.09.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.09.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.2.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.3.ce-1.el7 docker-ce-stable
docker-ce.x86_64 17.03.2.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable

* base: centos.ustc.edu.cn
Available Packages

# Since only stable warehouses are opened in repo by default, the latest stable version (18.09.2) is installed here
# Because the kernel is 3.10 and cannot run 18.06.x and above docker normally, it is not installed in this way
# yum install -y docker-ce

# After testing, it is found that the 3.10 kernel can run 18.03.1.ce
# yum install -y <FQPN>
yum install -y docker-ce-18.03.1.ce

# Start up and join start up
systemctl start docker
systemctl enable docker

# Verify whether the installation is successful (two parts, client and service, indicate that the installation and startup of docker are successful)
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

Change configuration if necessary

sudo vim /lib/systemd/system/docker.service

ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --graph=/home/docker/data

# You may use a proxy (you can add it if you don't have an Environment)
Environment="HTTP_PROXY=http://0.0.0.0:8123" "HTTPS_PROXY=http://0.0.0.0:8123" "NO_PROXY=localhost,127.0.0.1,::1"

Restart docker for configuration to take effect

sudo systemctl daemon-reload
sudo systemctl restart docker

Install docker compose

By visiting https://github.com/docker/compose/releases/latest Get the latest version of docker compose (for example: 1.23.2), and then execute the following command to install docker compose

# Download the latest version of docker compose to the directory / usr/bin
curl -L https://github.com/docker/compose/releases/download/1.23.2/docker-compose-`uname -s`-`uname -m` -o /usr/bin/docker-compose

# Authorize docker compose
chmod +x /usr/bin/docker-compose

FAQ

1. yum update -y failed

 
[root@localhost ~]# yum update -y
Loaded plugins: fastestmirror, langpacks
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"


 One of the configured repositories failed (Unknown),
 and yum doesn't have enough cached data to continue. At this point the only
 safe thing yum can do is fail. There are a few ways to work "fix" this:

     1. Contact the upstream for the repository and get them to fix the problem.

     2. Reconfigure the baseurl/etc. for the repository, to point to a working
        upstream. This is most often useful if you are using a newer
        distribution release than is supported by the repository (and the
        packages for the previous distribution release still work).

     3. Disable the repository, so yum won't use it by default. Yum will then
        just ignore the repository until you permanently enable it again or use
        --enablerepo for temporary usage:

            yum-config-manager --disable <repoid>

     4. Configure the failing repository to be skipped, if it is unavailable.
        Note that yum will try to contact the repo. when it runs most commands,
        so will have to try and fail each time (and thus. yum will be be much
        slower). If it is a very temporary problem though, this is often a nice
        compromise:

            yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true

Cannot find a valid baseurl for repo: base/7/x86_64

If the above error is encountered, modify / etc/resolv.conf, add the following content, and execute yum update -y again

 
nameserver 8.8.8.8
search localdomain

2. yum install -y docker-ce-18.03.1.ce failed

 
Transaction check error:
  file /usr/bin/docker from install of docker-ce-18.03.1.ce-1.el7.centos.x86_64 conflicts with file from package docker-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64
  file /usr/bin/docker-containerd from install of docker-ce-18.03.1.ce-1.el7.centos.x86_64 conflicts with file from package docker-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64
  file /usr/bin/docker-containerd-shim from install of docker-ce-18.03.1.ce-1.el7.centos.x86_64 conflicts with file from package docker-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64
  file /usr/bin/dockerd from install of docker-ce-18.03.1.ce-1.el7.centos.x86_64 conflicts with file from package docker-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64

Uninstall old version of package

 
yum erase docker-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64

Install docker again

 
yum install -y docker-ce-18.03.1.ce

 

Keywords: Operation & Maintenance Docker CentOS yum Linux

Added by ShaolinF on Thu, 07 May 2020 18:19:26 +0300