How to install Docker and Docker Compose offline

This tutorial is based on Red Hat Linux distribution. Altough it will work for most rpm based Linux distributions, it will not work on Windows OS, or non-rpm based Linux distributions, without proper adaptations.

The context

I found myself in the situation when I had to install Docker and Docker compose on a Red Hat server with no internet connection. In this tutorial, I will share the solution that worked for me.

Note: The versions of the rpm packages described in this tutorial are the latest at the time of the writing, but they will change in the future. Regardless of the versions on the time of your reading, I recommend the installation of the latest versions of the rpm packages, unless you are constrained by requirements to use specific versions.

The downloads presented in the tutorial are supposed to be done on a computer that has internet connection, and the installs can be performed on any target host, assuming that you have copied the files to that host.

Docker offline installation

Before starting the installation, here is the list of the rpm packages, dependecies included, that you will have to download using a computer connected to the internet:

  1. audit-libs-python-2.8.5-4.el7.x86_64.rpm
  2. checkpolicy-2.5-8.el7.x86_64.rpm
  3. libcgroup-0.41-21.el7.x86_64.rpm
  4. libseccomp-2.3.1-4.el7.x86_64.rpm
  5. libsemanage-2.5-14.el7.x86_64.rpm
  6. policycoreutils-python-2.5-34.el7.x86_64.rpm
  7. python-IPy-0.75-6.el7.noarch.rpm
  8. setools-libs-3.3.8-4.el7.x86_64.rpm
  9. containerd.io-1.4.3-3.1.el7.x86_64.rpm
  10. docker-ce-cli-20.10.3-3.el7.x86_64.rpm
  11. docker-ce-rootless-extras-20.10.3-3.el7.x86_64.rpm
  12. container-selinux-2.107-3.el7.noarch.rpm
  13. docker-ce-20.10.3-3.el7.x86_64.rpm

Let's go through the installation process.

As the root user, copy the first 8 rpm files into the /root/docker directory, the next 3 rpm files into /root/docker/rpm, and the last 2 files into /root/docker/rpm2:

[root@testuser1-host docker]# pwd
/root/docker

[root@testuser1-host docker]# ll
-rwxrwxrwx. 1 root root  78256 Feb 24 21:43 audit-libs-python-2.8.5-4.el7.x86_64.rpm
-rwxrwxrwx. 1 root root 302068 Feb 24 21:43 checkpolicy-2.5-8.el7.x86_64.rpm
-rwxrwxrwx. 1 root root  67720 Feb 24 21:43 libcgroup-0.41-21.el7.x86_64.rpm
-rwxrwxrwx. 1 root root  57460 Feb 24 21:43 libseccomp-2.3.1-4.el7.x86_64.rpm
-rwxrwxrwx. 1 root root 154244 Feb 24 21:43 libsemanage-2.5-14.el7.x86_64.rpm
-rwxrwxrwx. 1 root root 468316 Feb 24 21:43 policycoreutils-python-2.5-34.el7.x86_64.rpm
-rwxrwxrwx. 1 root root  32880 Feb 24 21:43 python-IPy-0.75-6.el7.noarch.rpm
drwxrwxrwx. 2 root root     96 Feb 24 21:43 rpm
drwxrwxrwx. 2 root root     96 Feb 24 21:43 rpm2
-rwxrwxrwx. 1 root root 635184 Feb 24 21:43 setools-libs-3.3.8-4.el7.x86_64.rpm

[root@testuser1-host docker]# cd rpm/
[root@testuser1-host rpm]# ll
-rw-r--r--. 1 root root 34677436 Feb 24 21:43 containerd.io-1.4.3-3.1.el7.x86_64.rpm
-rw-r--r--. 1 root root 34721064 Feb 24 21:43 docker-ce-cli-20.10.3-3.el7.x86_64.rpm
-rw-r--r--. 1 root root  9486464 Feb 24 21:43 docker-ce-rootless-extras-20.10.3-3.el7.x86_64.rpm

[root@testuser1-host rpm]# cd ../rpm2/
[root@testuser1-host rpm2]# ll
-rwxrwxrwx. 1 root root    40212 Feb 24 21:43 container-selinux-2.107-3.el7.noarch.rpm
-rwxrwxrwx. 1 root root 27887312 Feb 24 21:43 docker-ce-20.10.3-3.el7.x86_64.rpm

Next, run the rpm commands to install the packages. Make sure you are in the right directory every time you run a command.


[root@testuser1-host docker]# pwd
/root/docker
[root@testuser1-host docker]# rpm -Uvh *.rpm --nodeps --force
[root@testuser1-host docker]# cd rpm/
[root@testuser1-host rpm]# rpm -Uvh *.rpm --nodeps --force
[root@testuser1-host rpm]# cd ../rpm2/
[root@testuser1-host rpm2]# rpm -Uvh container-selinux-2.107-3.el7.noarch.rpm
[root@testuser1-host rpm2]# rpm -Uvh docker-ce-20.10.3-3.el7.x86_64.rpm

If you want docker service to automatically run at system start-up, you should enable the docker service. If you don't want docker service to automatically run at system start-up, skip the enable command:


[root@testuser1-host rpm2]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@testuser1-host rpm2]# systemctl start docker

You can check the status of the docker service:


[root@testuser1-host rpm2]# systemctl status docker
? docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2021-02-24 21:57:31 UTC; 5s ago
     Docs: https://docs.docker.com
 Main PID: 32601 (dockerd)
    Tasks: 24
   Memory: 40.5M
   CGroup: /system.slice/docker.service
           +-32601 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Feb 24 21:57:31 testuser1-host dockerd[32601]: time="2021-02-24T21:57:31.088578543Z" level=info msg="scheme \"unix\" not registered, f...le=grpc
Feb 24 21:57:31 testuser1-host dockerd[32601]: time="2021-02-24T21:57:31.088617761Z" level=info msg="ccResolverWrapper: sending update...le=grpc
Feb 24 21:57:31 testuser1-host dockerd[32601]: time="2021-02-24T21:57:31.088655351Z" level=info msg="ClientConn switching balancer to ...le=grpc
Feb 24 21:57:31 testuser1-host dockerd[32601]: time="2021-02-24T21:57:31.119767926Z" level=info msg="Loading containers: start."
Feb 24 21:57:31 testuser1-host dockerd[32601]: time="2021-02-24T21:57:31.499757081Z" level=info msg="Default bridge (docker0) is assig...ddress"
Feb 24 21:57:31 testuser1-host dockerd[32601]: time="2021-02-24T21:57:31.588762122Z" level=info msg="Loading containers: done."
Feb 24 21:57:31 testuser1-host dockerd[32601]: time="2021-02-24T21:57:31.624714568Z" level=info msg="Docker daemon" commit=46229ca gra...20.10.3
Feb 24 21:57:31 testuser1-host dockerd[32601]: time="2021-02-24T21:57:31.625035818Z" level=info msg="Daemon has completed initialization"
Feb 24 21:57:31 testuser1-host systemd[1]: Started Docker Application Container Engine.
Feb 24 21:57:31 testuser1-host dockerd[32601]: time="2021-02-24T21:57:31.673477489Z" level=info msg="API listen on /var/run/docker.sock"
Hint: Some lines were ellipsized, use -l to show in full.

Check the Docker version:


[root@testuser1-host rpm2]# docker -v
Docker version 20.10.3, build 48d30b5

At this point, you have successfully installed and enabled Docker.


Docker Compose offline installation

  1. Download Docker Compose file (docker-compose-Linux-x86_64), using the following command:


    $ wget https://github.com/docker/compose/releases/download/1.28.4/docker-compose-Linux-x86_64

  2. Using the following command, move the downloaded file to /usr/local/bin and rename it "docker-compose”:


    $ sudo mv docker-compose-Linux-x86_64 /usr/local/bin/docker-compose

  3. Now, you have to add executable permissions for docker-compose:


    $ sudo chmod +x /usr/local/bin/docker-compose

  4. Check that the installation is successful:


    $ docker-compose -v
    docker-compose version 1.28.4, build cabd5cfb

  5. At this point, you have successfully installed Docker Compose.

Other articles:

How to use bash Environment Variables in Python - part 1

How to use bash Environment Variables in Python - part 2

How to use bash Environment Variables in Python - part 3

How to plot multiple functions on the same figure using Matplotlib