How can I customize a yum .repo file in a Dockerfile so it can be used as a source when installing packages?

10,550

There are 9 YUM# variables available for substitution in URLs (and a few other places) inside yum repo files.

If the variables are set in the environment when yum runs it will substitute them in to the appropriate places in the URLs in the repo files.

In CentOS 6+ there is also the /etc/yum/vars directory which can contain arbitrary files whose filename is the yum variable name and whose first line is the variable value (allowing freedom to name the variables in the .repo files).

So assuming you are using a new enough version of CentOS (6+) you should just be able to create those files and then your repo file can use them and be static.

The variables work just like the default $releasever, $arch, etc.

Share:
10,550
codecraig
Author by

codecraig

Updated on June 04, 2022

Comments

  • codecraig
    codecraig almost 2 years

    I have a private YUM repository hosted in a Docker container. I'd like to stand up another Docker container that knows about this private repository and uses it to install packages, something like:

    ADD myrepo.repo /etc/yum.repos.d/myrepo.repo
    RUN yum install -y custompackage
    

    The issue is the baseurl in myrepo.repo needs to be configurable, ideally I'd like to set an environment variable when doing docker run -e MY_REPO_HOST=1.2.3.4 ...

    Any thoughts?