Upgrading Docker Installed via yum
1. Background
Generally, the default Docker version installed via yum is quite old, which sometimes causes issues with docker build because it can't parse certain syntax. So we need to update our yum-installed Docker.
2. Solution
Source: Install Docker Engine on CentOS
2.1 Uninstall Old Version
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
It's OK if yum reports that none of these packages are installed.
The contents of /var/lib/docker/, including images, containers, volumes, and networks, are preserved. The Docker Engine package is now called docker-ce.
2.2 Installation Methods
You can install Docker Engine in different ways depending on your needs:
- Most users set up Docker's repositories and install from them for ease of installation and upgrade tasks. This is the recommended approach.
- Some users download the RPM package and install it manually and manage upgrades completely manually. This is useful in situations such as installing Docker on air-gapped systems with no access to the internet.
- In testing and development environments, some users choose to use automated convenience scripts to install Docker.
2.3 Set Up Repository
Install the yum-utils package (which provides the yum-config-manager utility) and set up the stable repository.
sudo yum install -y yum-utils
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
2.4 Install Docker Engine
- Install the latest version of Docker Engine and containerd, or go to the next step to install a specific version:
sudo yum install docker-ce docker-ce-cli containerd.io
- To install a specific version of Docker Engine, list the available versions in the repo, then select and install: List and sort the versions available in your repo. This example sorts results by version number, highest to lowest, and is truncated:
yum list docker-ce --showduplicates | sort -r
The list returned depends on which repositories are enabled, and is specific to your version of CentOS (indicated by the .el7 suffix in this example).
Install a specific version by its fully qualified package name, which is the package name (docker-ce) plus the version string (2nd column) starting at the first colon (:), up to the first hyphen, separated by a hyphen (-). For example, docker-ce-18.09.1.
sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
This command installs Docker, but doesn't start Docker. It also creates a docker group, however, it doesn't add any users to the group by default.
- Start Docker.
sudo systemctl start docker
- Verify that Docker Engine is installed correctly by running the
hello-worldimage.
sudo docker run hello-world
This command downloads a test image and runs it in a container. When the container runs, it prints a message and exits.
3. Possible Issues
3.1 After Docker upgrade or reinstall, starting container shows: Error response from daemon: Unknown runtime specified docker-runc
3.1.1 Solution:
Change the file parameters in the /var/lib/docker/containers directory, replacing docker-runc with runc:
grep -rl 'docker-runc' /var/lib/docker/containers/ | xargs sed -i 's/docker-runc/runc/g'
Note:
- grep -rl: Recursively search directories and subdirectories, only listing filenames containing matching text lines, without showing specific match content
- xargs: Chains execution with previously obtained values
Overall meaning: Search for files containing 'docker-runc' in /var/lib/docker/containers and replace 'docker-runc' with runc.
Restart Docker:
sudo systemctl daemon-reload
sudo systemctl restart docker
Done!