How to install Docker on CentOS Offline

Share on Social Media

Discover how to install Docker on CentOS offline with our detailed guide. Follow step-by-step instructions to set up Docker without an internet connection, ensuring a smooth and successful installation. #centlinux #linux #docker

What is Docker?

Docker is a computer software, that performs operating-system-level virtualization, also known as Containerization. Docker is developed by Docker Inc. Docker uses predefined and custom images to create and run containers. These images are provided through Docker Hub (an online Docker registry).

Containers are isolated from each other having their own set of binaries, libraries and configuration files. Unlike virtual machines, containers may or may not have their own operating systems. The containers are run by the host operating system Kernel, therefore, a container is much light weight as compare to a Hypervisor based virtual machine.

Docker is an important part of today’s DevOps environments, where it is mostly used for application virtualization..

Docker is a freemium software. Because a Community Edition (CE)  with limited features is available as free while an Enterprise Edition (EE) is available with more features and a license cost.

Docker is also provided with Red Hat Atomic Host 7, which is a RHEL 7 based operating system optimized for hosting containers. You can read our previous guide about installation of Red Hat Atomic Host 7.

Read Also: How to install Docker on Rocky Linux 9

Environment Specification

In this article, we are using two isolated CentOS 7 based Linux servers. One server has access to Internet, while the other server isn’t connected with Internet.

 Offline ServerOnline Server
Hostname:docker-offline.example.comdocker-online.example.com
Operating System:CentOS 7.6CentOS 7.6
Internet:NoYes

Linux operating systems on both machines must be same, otherwise the software package versions may not matched and it won’t work.

Recommended Online Training: Docker and Kubernetes – The Complete Developers Guide

4732132 bd4c 4show?id=oLRJ54lcVEg&offerid=1628165.4732132&bids=1628165

Install EPEL Yum Repository on CentOS 7

By using a ssh client, connect with docker-online.example.com as root user.

To install Docker on CentOS offline, we requires some software packages that are available in EPEL (Extra Packages for Enterprise Linux) yum repository. Therefore, we have to install EPEL yum repository first.

# yum install -y epel-release.noarch

EPEL yum repository has been installed.

Install Docker Yum Repository on CentOS 7

Install Docker CE yum repository on our CentOS 7 operating system.

# yum-config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
Loaded plugins: 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

Enable Docker CE (Nightly) yum repository.

# yum-config-manager --enable docker-ce-nightly

We have added two yum repositories in our Linux server. Therefore, we should build cache for yum package manager.

# yum makecache fast
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                     | 9.1 kB     00:00
 * base: repo.inara.pk
 * epel: sg.fedora.ipserverone.com
 * extras: repo.inara.pk
 * updates: repo.inara.pk
base                                                     | 3.6 kB     00:00
docker-ce-nightly                                        | 3.5 kB     00:00
docker-ce-stable                                         | 3.5 kB     00:00
extras                                                   | 3.4 kB     00:00
updates                                                  | 3.4 kB     00:00
Metadata Cache Created

Download Docker CE and Software Dependencies

Create a directory to download Docker CE and dependent software packages.

# mkdir ~/docker
# cd ~/docker

Download Docker CE and dependent packages following Linux command.

# yumdownloader --resolve docker-ce

Docker CE and dependent software packages has been downloaded.

# ls
audit-libs-python-2.8.4-4.el7.x86_64.rpm
checkpolicy-2.5-8.el7.x86_64.rpm
containerd.io-1.2.2-3.el7.x86_64.rpm
container-selinux-2.74-1.el7.noarch.rpm
docker-ce-18.09.1-3.el7.x86_64.rpm
docker-ce-cli-18.09.1-3.el7.x86_64.rpm
libcgroup-0.41-20.el7.x86_64.rpm
libseccomp-2.3.1-3.el7.x86_64.rpm
libsemanage-python-2.5-14.el7.x86_64.rpm
policycoreutils-2.5-29.el7_6.1.x86_64.rpm
policycoreutils-python-2.5-29.el7_6.1.x86_64.rpm
python-IPy-0.75-6.el7.noarch.rpm
setools-libs-3.3.8-4.el7.x86_64.rpm

The above packages versions may be different on your Linux server due to the Kernel version that your are using.

Now, we need to transfer these files to docker-offline.example.com. Therefore, we are creating a tarball of all downloaded software packages.

# tar czf ~/docker.tar.gz *

Now, we have a tarball of Docker CE and dependent software packages.

# ls ~ -lh
total 58M
-rw-------. 1 root root 1.5K Dec 22 11:29 anaconda-ks.cfg
drwxr-xr-x. 2 root root 4.0K Feb  8 21:32 docker
-rw-r--r--. 1 root root  58M Feb  8 21:39 docker.tar.gz

Install Docker on CentOS Offline

Transfer the docker.tar.gz tarball to docker-offline.example.com and copy at home directory of root user.

# ls -lh
total 58M
-rw-------. 1 root root 1.5K Dec 22 12:23 anaconda-ks.cfg
-rw-r--r--. 1 root root  58M Feb  8 21:39 docker.tar.gz

Extract the docker.tar.gz tarball.

# mkdir docker
# tar xf docker.tar.gz -C ~/docker

You can now install Docker on CentOS offline by installing all packages from the ~/docker directory.

# cd docker
# rpm -ivh --replacefiles --replacepkgs *.rpm
warning: containerd.io-1.2.2-3.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:policycoreutils-2.5-29.el7_6.1   ################################# [  8%]
   2:libcgroup-0.41-20.el7            ################################# [ 15%]
   3:setools-libs-3.3.8-4.el7         ################################# [ 23%]
   4:python-IPy-0.75-6.el7            ################################# [ 31%]
   5:libsemanage-python-2.5-14.el7    ################################# [ 38%]
   6:libseccomp-2.3.1-3.el7           ################################# [ 46%]
   7:docker-ce-cli-1:18.09.1-3.el7    ################################# [ 54%]
   8:containerd.io-1.2.2-3.el7        ################################# [ 62%]
   9:checkpolicy-2.5-8.el7            ################################# [ 69%]
  10:audit-libs-python-2.8.4-4.el7    ################################# [ 77%]
  11:policycoreutils-python-2.5-29.el7################################# [ 85%]
  12:container-selinux-2:2.74-1.el7   ################################# [ 92%]
  13:docker-ce-3:18.09.1-3.el7        ################################# [100%]

Start and enable Docker service.

# systemctl enable docker.service
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
# systemctl start docker.service

We have successfully installed Docker CE on an offline Linux server.

Download Docker images from Docker Hub

To create containers,  we required Docker images, that are available via Docker Hub or a Private Docker Registry server.

Since, our Linux server is not connected to Internet, therefore, we cannot pull Docker images directly from Docker Hub.

The workaround of this problem is to download Docker images on an online system and then transfer and load these images to our offline CentOS 7 server.

Note: You must have Docker CE installed on the online system first. Because we will use the docker command to download and save images from Docker Hub.

# docker pull jenkins/jenkins
Using default tag: latest
latest: Pulling from jenkins/jenkins
8700b2d54fbc: Pull complete
4613d2e35dec: Pull complete
08320da45709: Pull complete
8f947c5bbe77: Pull complete
51cf55002ec2: Pull complete
9537066ae19a: Pull complete
e156275467ac: Pull complete
Digest: sha256:20981c20164347728fca4774b3c45f5d24a73d857e8b9b8e6faf4100cfc0812d
Status: Downloaded newer image for jenkins/jenkins:latest

Similarly, pull more images according to your requirement.

Save Jenkins image in a tar file.

# docker save jenkins/jenkins > ~/jenkins.tar
# ls -lh
total 690M
-rw-------. 1 root root 1.5K Dec 22 11:29 anaconda-ks.cfg
-rw-r--r--. 1 root root 690M Feb 12 22:07 jenkins.tar

Transfer jenkins.tar to docker-offline.example.com.

Load jenkins.tar image by using docker command.

# docker load < jenkins.tar
13d5529fd232: Loading layer  105.6MB/105.6MB
abc3250a6c7f: Loading layer  24.07MB/24.07MB
5924ca705d38: Loading layer  9.216kB/9.216kB
852edd42bb1e: Loading layer  4.608kB/4.608kB
03b3a4ed2e5a: Loading layer  3.072kB/3.072kB
37dfb8384dfe: Loading layer  7.168kB/7.168kB
8f65ce1dc902: Loading layer  12.29kB/12.29kB
Loaded image: jenkins/jenkins:latest

Jenkins image has been loaded into Docker. You can use following Linux command to verify this.

# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
jenkins/jenkins     latest              9b74eda1c268        32 hours ago        704MB

Now, we can create and run Docker containers from the Jenkins/Jenkins image.

To start using Docker you should refer to Docker Documentation or buy and read Docker Deep Dive (PAID LINK).

Final Thoughts

Installing Docker on CentOS offline can be a bit challenging, but with the right steps, it becomes manageable. This guide aims to make the process straightforward and successful. If you need further assistance or prefer to have an expert handle the installation, I’m here to help.

I offer professional services for Docker installation and configuration. Visit my Fiverr profile to learn more and get started: Docker Containers Expert

Ensure a smooth and efficient Docker setup on CentOS with expert support today!

10 thoughts on “How to install Docker on CentOS Offline”

  1. Add the following directive in /etc/yum.repos.d/docker-ce.repo to enable old versions of Docker.

    obsoletes=0

    Thereafter, execute following command to install your required Docker version.

    dnf install docker-ce-18.09*

Leave a Comment