Contents
Installing Docker Engine CE (Community Edition) on CentOS Linux 7
Prerequisites
OS Requirements
To install Docker CE, the maintained version of CentOS Linux 7 is mandatory. Archived versions are not supported or tested. You must enable the centos-extras repository.
Uninstall Earlier Versions
Uninstall the earlier versions of Docker/Docker-engine along with associated dependencies using the following commands:
- $ sudo yum remove docker \
- docker-common\
- docker-selinux \
- docker-engine
Though YUM reports that the packages are not installed, the contents available in /var/lib/docker/ are saved, including images, containers, volumes and networks. The Docker CE package is now changed to Docker-ce. Previously, the package name was Docker.
Install Docker CE
You can install Docker CE using one of the following methods:
- Install using the repository (most common method)
- Install manually using RPM package
- Install using automated scripts
Install Using the Repository
- Set up the repository.
- Install required packages. yum-utils provides the yum-config-manager utility. The devicemapper storage driver requires the packages device-mapper-persistent-data and lvm2 for installation.
- $ sudo yum install -y yum-utils \
- device-mapper-persistent-data \
- lvm2
- Set up the stable repository by using the following command. You need a stable repository, even if you want to install builds from the edge or test repositories.
- $ sudo yum-config-manager \
- --add-repo \
- https://download.docker.com/linux/centos/docker-ce.repo
- Install Docker CE.
- Install the latest version of Docker CE.
- $ sudo yum install docker-ce
- If you are installing a package from a recently added repository for the first time, you will be prompted to accept the GPG key, and the key’s fingerprint will be displayed. Check if the fingerprint is correct. If the fingerprint is correct, accept the key. The fingerprint should match 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35.
- Docker is now installed, but not started. The Docker group is created. However, no users are added to the group.
- ImportantIf you receive an error message stating that Parallel gzip (pigz) or container-selinux is not installed, you must install them. The following example provides commands on how to install pigz and container-selinux from the repository. These commands are used for installing pigz version 2.3.4-1.e17 and container-selinux version 2.21-1.el7, which are the latest versions. Please visit the repository URLS http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/p/ for pigz, and http://mirror.centos.org/centos/7/extras/x86_64/Packages/ for container-selinux to view the latest versions of both the packages.
- Command to install pigz
- yum install http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/p/pigz-2.3.4-1.el7.x86_64.rpm
- Command to install container-selinux
- yum install http://mirror.centos.org/centos/7/extras/x86_64/Packages/container-selinux-2.21-1.el7.noarch.rpm
- Re-run the Docker installation after installing pigz and container-selinux.
- Install a specific version of Docker CE.
- yum list docker-ce --showduplicates | sort -r
- docker-ce.x86_64 17.09.ce-1.el7.centos docker-ce-stable
- The contents of the list depend on the repositories that are enabled. These contents will be specific to your version of CentOS (indicated by the .el7 suffix on the version in the preceding example). Select a specific version to install. The second column is the version string. You can use the entire version string. You must include at least to the first hyphen. The third column is the repository name, which indicates which repository the package is from and by extension its stability level. To install a specific version, append the version string to the package name and separate them by a hyphen (-).
- ImportantThe version string is the package name including the version up to the first hyphen. In the preceding example, the fully qualified package name is docker-ce-17.06.1.ce.
- $ sudo yum install <FULLY-QUALIFIED-PACKAGE-NAME>
- Install the latest version of Docker CE.
- Start Docker.
- $ sudo systemctl start docker
- Run the hello-world image to ensure Docker is installed correctly.
- sudo docker run hello-world
- This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits.
Install Manually Using the RPM Package
If you cannot use Docker’s repository to install Docker, you can download the .rpm file and install it manually. You will need to download a new file each time you want to upgrade Docker.
- Go to
https://download.docker.com/linux/centos/7/x86_64/stable/Packages/ and download the .rpm file for the Docker version that you want to install.
- ImportantTo install an edge package, change the word stable in the above URL to the word edge.
- Install Docker CE, changing the path below to the path where you downloaded the Docker package.
- $ sudo yum install /path/to/package.rpm
- Docker is now installed, but not started. The Docker group is created, but no users are added to the group.
- Start Docker.
- $ sudo systemctl start docker
- Run the hello-world image to ensure Docker is installed correctly.
- sudo docker run hello-world
Docker CE is now installed and running. You need to use sudo to run the Docker commands. For more information about the installation of Docker engine, refer to Docker documentation: https://docs.docker.com/engine/installation/linux/docker-ce/centos.
Install Using Automated Scripts
Docker provides scripts at https://get.docker.com/ and https://test.docker.com/ for installing edge and testing versions of Docker CE in development environments, quickly and non-interactively. The source code for these scripts is available at https://github.com/docker/docker-install. However, using these scripts is not recommended for production environments.