If you’ve ever needed to install rpms on servers that are cut-off from the internet, but you still want those rpms to managed by dnf (the replacement for yum in Rocky8) this quick tutorial is for you.

What you’ll need:

  1. A Rocky 8 Linux host connected to the internet
  2. A Rocky 8 Linux host not connected to the internet
  3. A way to copy files between them. On my example I have a linux host that can connect to #1 and #2.

On Your Internet Connected Linux Host

Download the package of interest and create a repo from the downloaded content, then tar that up. In this case let’s use docker community edition as an example:

[vagrant@internet-rocky8 ~]$ sudo dnf install --downloadonly --installroot=/tmp/docker-ce-installroot --releasever=8 --downloaddir=/tmp/docker-ce -y docker-ce
[vagrant@internet-rocky8 ~]$ sudo createrepo --database /tmp/docker-ce
[vagrant@internet-rocky8 ~]$ tar -czvf docker-ce.tar.gz /tmp/docker-ce

On Your Linux Host That Can Connect To Both

Download the archive and copy up to the linux host not connected to the internet

On Your Non-Internet Connected Linux Host

Extract the archive to tmp directory:

[vagrant@nointernet-rocky8 ~]$ tar -xzvf docker-ce.tar.gz --directory /

Create a new repo file with the following contents:

[vagrant@nointernet-rocky8 ~]$ cat /etc/yum.repos.d/offline-docker-ce.repo
[offline-docker-ce]
name=offline-docker-ce
baseurl=file:///tmp/docker-ce/
enabled=1
module_hotfixes=true

Clear and then re-create the dnf cache:

[vagrant@nointernet-rocky8 ~]$ sudo dnf clean all
[vagrant@nointernet-rocky8 ~]$ sudo dnf makecache

Check to see if your packages show up as options when all repos except your local offline ones are blocked:

[vagrant@nointernet-rocky8 ~]$ sudo dnf --disablerepo=* --enablerepo=offline* list available

Assuming they do show up, go ahead and install them like this:

[vagrant@nointernet-rocky8 ~]$ sudo dnf --disablerepo=* --enablerepo=offline-docker-ce -y --nogpgcheck install docker-ce docker-ce-cli containerd.io

Now not only do you have your rpms installed, but their origin can be determined as coming from a local repo when you query dnf:

[vagrant@nointernet-rocky8 ~]$ dnf info docker-ce
...
Installed Packages
Name         : docker-ce
Epoch        : 3
Version      : 23.0.4
Release      : 1.el8
Architecture : x86_64
Size         : 94 M
Source       : docker-ce-23.0.4-1.el8.src.rpm
Repository   : @System
From repo    : offline-docker-ce
Summary      : The open-source application container engine
URL          : https://www.docker.com
License      : ASL 2.0
Description  : Docker is a product for you to build, ship and run any application as a
             : lightweight container.
             :
             : Docker containers are both hardware-agnostic and platform-agnostic. This means
             : they can run anywhere, from your laptop to the largest cloud compute instance
             : and everything in between - and they don't require you to use a particular
             : language, framework or packaging system. That makes them great building blocks
             : for deploying and scaling web apps, databases, and backend services without
             : depending on a particular stack or provider.