Just like the blogs I wrote before: Offline Package Installation I
and Solve Conflicts in RPM installation
, Use rpm
or bare yum
command to install downloaded rpm file works but I find somehow this will cause some maintenance problems, for example
1 | Warning: RPMDB altered outside of yum. |
I need to find a way that can automatically figure out the dependency chain, install the rpm required from download pool.
Create a yum repository
Install createrepo
package:
1 | yum install -y createrepo |
Next, creates the necessary metadata for your Yum repository, as well as the sqlite database for speeding up yum operations. For example, /root/docker
directory contains all rpms that install docker needs:
1 | createrepo --database /root/docker |
you will find it generates a folder called repodata
that contains:
1 | 304457af78cd250275222993fa0da09256f64cc627c1e31fb3ec0848b28b28d8-primary.xml.gz |
Create yum repo file
To define a new repository, you can either add a [repository]
section to the /etc/yum.conf
file, or to a .repo
file in the /etc/yum.repos.d/
directory. All files with the .repo
file extension in this directory are read by yum, and it is recommended to define your repositories here instead of in /etc/yum.conf
.
For example, create a docker-local.repo
file in /etc/yum.repos.d/
directory, baseurl
points to the folder that holds downloaded rpms:
1 | [docker-local.repo] |
Then if you run yum repolist all
, you will see this new added yum repository:
1 | yum repolist all |
You can also list enabled and disabled repository:
1 | yum repolist enabled |
Install using yum
Now you can install docker by running:
1 | yum install -y docker-ce |
yum will check local repository and launch dependencies for you.
Sometimes it’s better to set enabled=0
in .repo
file to disable it by default, so you can run:
1 | yum --enablerepo=docker-local.repo install -y docker-ce |