Search code examples
dockermount

Mount-ing a CDROM repo during docker build


I'm building a docker image which also involves a small yum install. I'm currently in a location where firewall's and access controls makes docker pull, yum install etc extremely slow.

In my case, its a JRE8 docker image using this official image script

My problem:

Building the image requires just 2 libraries (gzip + tar) which combined is only of (132 kB + 865 kB). But the yum inside docker build script will first download the repo information which is over 80 MB. While 80 MB is generally small, here, this took over 1 hour just to download. If my colleagues need to build, this would be sheer waste of productive time, not to mention frustration.

Workarounds I'm aware of:

  • Since this image may not need the full yum power, I can simply grab the *.rpm files, COPY in container script and use rpm -i instead of yum
  • I can save the built image and locally distribute
  • I could also find closest mirror for docker-hub, but not yum

My bet:

  • I've copy of the linux CD with about the same version
  • I can add commands in dockerfile to rename the *.repo to *.repo.old
  • Add a cdrom.repo in /etc/yum.repos.d/ inside the container
  • Use yum to load most common libraries from the CDROM instead of internet

My problem:

I'm not able to make out how to create a mount point to a cdrom repo from inside the container build without using httpd.

In plain linux I do this:

mkdir /cdrom
mount /dev/cdrom /cdrom

cat > /etc/yum.repos.d/cdrom.repo <<EOF
[cdrom]
name=CDROM Repo
baseurl=file:///cdrom
enabled=1
gpgcheck=1
gpgkey=file:///cdrom/RPM-GPG-KEY-oracle
EOF

Any help appreciated.


Solution

  • Docker containers cannot access host devices. I think you will have to write a wrapper script around the docker build command to do the following

    1. First mount the CD ROM to a directory within the docker context ( that would be a sub-directory where your DockerFile exists).
    2. call docker build command using contents from this directory
    3. Un-mount the CD ROM.

    so,

    cd docker_build_dir
    mkdir cdrom
    mount /dev/cdrom cdrom
    docker build "$@" .
    umount cdrom
    

    In the DockerFile, you would simple do this:

    RUN cd cdrom && rpm -ivh rpms_you_need