How to Upgrade Docker on Fedora / CentOS

Docker is an open source platform for developing, shipping, and running applications. Docker v17.12 is the latest stable release as of writing this article. It provides the ability to package and run an application in a totally isolated environment called a container. We can run many containers simultaneously on a given host. Containers are lightweight and fast because they don’t need a hypervisor, but run directly within the host machine’s kernel.

Docker Architecture

Docker is a client-server application, where both client and daemon can be run on the same system or you can connect a Docker client with a remote Docker daemon. Docker clients and daemon communicates via sockets or RESTful API (Representational State Transfer - it is a stateless transfer over HTTP of a webpage containing an XML file that includes and describes the desired content).

4624570-ac68e21a0f434a87.png
docker architecture

The main components of Docker are

  • Docker Daemon: The Docker daemon (dockerd) listens for Docker API requests and manages Docker objects such as images, containers, networks, and volumes. A daemon can also communicate with other daemons to manage Docker services.
  • Docker Client: The Docker client (docker) is the primary way where Docker users interact with Docker. When we use commands such as docker run, docker build etc the client sends these commands to docker daemon(dockerd), which carries them out. The docker command uses the Docker API. It can communicate with more than one daemon.
  • Docker Registry (2.4.1): A Docker registry stores Docker images. Docker Hub and Docker Cloud are public registries that anyone can use. By default, Docker is configured to look for images on Docker Hub. We can even setup our own private registr for our images.

In this article, I'll explain how you can upgrade your Docker to the latest available version on both CentOS 7 and Fedora 27.

Pre-requisites

Inorder to install Docker CE version, we need a maintained version of CentOS 7. The centos-extras repository must be enabled. This repository is enabled by default, but if you have disabled it, you need to re-enable it.

Upgrading Docker on CentOS 7.4

For upgrading Docker, it's recommended to install Docker Community Edition (Docker CE) which will help you to install, upgrade, and maintain Docker with the support and assurances required for your particular workload. The overlay2 storage driver is recommended. overlay2 is the default choice for Docker CE. The storage driver controls how images and containers are stored and managed on your Docker host. Docker supports several different storage drivers. The devicemapperis our next choice, but it requires direct-lvmfor production environments for better performance.

Let's start with the steps to upgrade your old Docker version.

  • Uninstall the old Docker versions

The docker and docker-engine packages are termed to be the old packages. If you're running these old versions, you can uninstall them first to proceed further. Run this command to remove all docker traces from your server.

#yum remove docker docker-common docker-selinux docker-engine

Evenif, those packages are removed from the server, all our required docker contents including images, containers, volumes, and networks, are preserved in the /var/lib/docker/folder.

  • Install Docker CE

You can setup Docker repositories first of all and install them using it. This will make the installation and upgrade process much easier with the same repository. For setting up our repository we need the yum-config-manager utility which is provided by the yum-utils package. And as discussed before, Docker CE prefers a storage driver, here we use devicemapper. Hence for this storage driver, we needs this device-mapper-persistent-data and lvm2 packages. We can install all these pre-requisites for setting up our repository using this command.

#yum install -y yum-utils device-mapper-persistent-data lvm2

Next, you can use the following command to enable the stable Docker Repository.

#yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# yum install docker-ce
Loaded plugins: fastestmirror
docker-ce-stable | 2.9 kB 00:00:00 
Loading mirror speeds from cached hostfile
* base: mirrors.coreix.net
* extras: repo.uk.bigstepcloud.com
* updates: mirror.sov.uk.goscomb.net
Resolving Dependencies
--> Running transaction check
---> Package docker-ce.x86_64 0:17.12.0.ce-1.el7.centos will be installed
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================================================================================================================================================
Package Arch Version Repository Size
============================================================================================================================================================================================================
Installing:
docker-ce x86_64 17.12.0.ce-1.el7.centos docker-ce-stable 30 M

Transaction Summary
============================================================================================================================================================================================================
Install 1 Package

This step is optional: Edge and test repositories are also included in this repo file, it's disabled by default. If you want you can enable those repo files as well alongside Stable repo and install the Edge or test versions available. This can be done by issuing the following command below:

#yum-config-manager --enable docker-ce-edge
#yum-config-manager --enable docker-ce-test

After enabling these repos, the install command will push the installation from the Edge Repo.

# yum install docker-ce
Dependencies Resolved

============================================================================================================================================================================================================
Package Arch Version Repository Size
============================================================================================================================================================================================================
Installing:
docker-ce x86_64 18.01.0.ce-1.el7.centos docker-ce-edge 33 M
Installing for dependencies:
libtool-ltdl x86_64 2.4.2-22.el7_3 base 49 k

Transaction Summary
============================================================================================================================================================================================================
Install 1 Package (+1 Dependent package)

So if you need the latest Stable version, you can just keep these Edge and Test repos disabled. You can use the yum-config-manager command with the --disable flag to disable these repos.

At times, there can be still some traces of old docker components present on the server evenif we executed yum removecommand as in step 1. During the installation, if there is any old docker versions available, it'll report error as below:

Transaction check error:
file /usr/bin/docker from install of docker-ce-18.01.0.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.01.0.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.01.0.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.01.0.ce-1.el7.centos.x86_64 conflicts with file from package docker-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64

I've manually removed these packages using yum remove command to proceed with the installation successfully as below:

# yum remove docker-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64
Dependencies Resolved

============================================================================================================================================================================================================
Package Arch Version Repository Size
============================================================================================================================================================================================================
Removing:
docker-common x86_64 2:1.12.6-68.gitec8512b.el7.centos @extras 4.5 k
Removing for dependencies:
docker-client x86_64 2:1.12.6-68.gitec8512b.el7.centos @extras 11 M

Transaction Summary
============================================================================================================================================================================================================
Remove 1 Package (+1 Dependent package)

Verifying the Docker installation

Once, the installation is complete, you can start and enable the docker service and verify the installation by running the hello-world image.

# systemctl start docker
# systemctl enable docker
# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2018-01-23 06:36:24 UTC; 2s ago
Docs: https://docs.docker.com
Main PID: 30700 (dockerd)
Memory: 23.1M
CGroup: /system.slice/docker.service
├─30700 /usr/bin/dockerd
└─30703 docker-containerd --config /var/run/docker/containerd/containerd.toml

# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete
Digest: sha256:66ef312bbac49c39a89aa9bcc3cb4f3c9e7de3788c944158df3ee0176d32b751
Status: Downloaded newer image for hello-world:latest

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://cloud.docker.com/

For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/

Upgrading the Docker CE

You can use the yum upgrade command to update your Docker version to its latest stable version in future. Currently, our server is already installed with the latest Stable Docker build available which is Docker 17.12 version.

# docker -v
Docker version 17.12.0-ce, build c97c6d6

Now, if we need to upgrade this current stable version to the latest available Edge version, you can just enable the edge repo file in the Docker repository and run yum upgrade command as below:

# yum-config-manager --enable docker-ce-edge
# yum upgrade docker-ce
Dependencies Resolved

============================================================================================================================================================================================================
Package Arch Version Repository Size
============================================================================================================================================================================================================
Updating:
docker-ce x86_64 18.01.0.ce-1.el7.centos docker-ce-edge 33 M

Transaction Summary
============================================================================================================================================================================================================
Upgrade 1 Package

This will install the latest Edge version available from the repository. You can confirm the Docker version after the installation. Please refer this documentation to learn more about Stable and Edge releases.

# docker -v
Docker version 18.01.0-ce, build 03596f5

Upgrading Docker on Fedora 27

As both Fedora and CentOS are from RedHat, commands used are pretty much identical except for the differences in the Docker package. Similar to the previous case, in Fedora too, we need to remove old docker versions available and install Docker Community Edition (Docker CE) for ease of installation and upgrade.

Pre-requisites

To install Docker, you need the 64-bit version of these latest Fedora 27 version

Lets' start with the steps to upgrade your old Docker version on Fedora.

  • Uninstall old Docker version

As discussed before, the docker and docker-engine packages are termed to be the old packages. You can remove these old packages with this command below:

#dnf remove docker docker-common docker-selinux docker-engine-selinux docker-engine

Evenif, those packages are removed from the server, all our required docker contents including images, containers, volumes, and networks, are preserved in the /var/lib/docker/ folder.

  • Install Docker CE

We need to enable the Docker repository for Fedora to install Docker CE version. In order to setup this repository, we need some of the commands to manage the dnf package manager. The dnf-plugins-core package provides the commands to manage your DNF repositories from the command line. You can install this using the command below:

# dnf -y install dnf-plugins-core

Now, we can use this command to enable the Stable repository and install the latest Stable version available from this repository using the dnf installcommand.

# dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
Adding repo from: https://download.docker.com/linux/fedora/docker-ce.repo

# dnf install docker-ce
Last metadata expiration check: 0:00:20 ago on Mon 22 Jan 2018 09:43:35 AM UTC.
Dependencies resolved.
============================================================================================================================================================================================================
Package Arch Version Repository Size
============================================================================================================================================================================================================
Installing:
docker-ce x86_64 17.12.0.ce-1.fc27 docker-ce-stable 31 M
Installing dependencies:
container-selinux noarch 2:2.38-1.fc27 updates 36 k
iptables x86_64 1.6.1-4.fc27 fedora 471 k
libnetfilter_conntrack x86_64 1.0.6-4.fc27 fedora 62 k
libnfnetlink x86_64 1.0.1-11.fc27 fedora 31 k
policycoreutils-python-utils x86_64 2.7-1.fc27 fedora 223 k

Transaction Summary
============================================================================================================================================================================================================
Install 6 Packages

As stated before, both Edge and Test repo files are present within this Docker Repository (docker.repo file). But both are disabled by default to enable the Stable tier alone. As required, you can enable it using these commands below:

# dnf config-manager --set-enabled docker-ce-edge
# dnf config-manager --set-enabled docker-ce-test

Upgrade Docker CE

Inorder to upgrade your Docker CE, you can use dnf -y upgrade. This will upgrade to the latest Stable tier available within the Docker repository.

#dnf -y upgrade docker-ce

Wrapping up

Though the docker technology is quite recent one, it is quickly gaining popularity. It has made life easy for developers and ops teams to quickly create and deploy applications respectively. With the company releasing quick updates to Docker in order to improve the product and address customer requirements, the future is definitely bright for Docker.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值