Is it possible to mount the directory when creating from the Dockerfile?

I am trying to create a Docker image using the Dockerfile method. Minimizing image size and number of layers is very important for this particular application. However, the speed required for installation is quite high, and I do not want to bake this image. It seems that if I use the ADD command in the Docker file, rpm will be copied to the image as its own layer, and there is no way to delete it after I have finished using it. To get around this, we simply launch the container interactively with the option to mount the -v volume to share the folder containing rpm, but without actually copying rpm to the container. Is there a way to do something like the -v option while running the docker build command using Dockerfiles?

+4
source share
2 answers

The method that an employee has encountered is to use docker runand docker commit:

docker run --name=$name --volume=$PWD/ToInstall/:/scratch --workdir=/scratch centos /scratch/install-script.sh
echo Status is $(docker wait $name)
echo
docker commit $name myname-base
docker rm -f $name

install-script.sh will look something like this:

set -eux
rpm -i myrpm1.rpm
rpm -i myrpm2.rpm

rm -rf /something-else-you-want-removed-from-layer

Ciao!

+2
source

When you put the RPM file in the same folder as the Docker file, you can access it from your file:

YourFolder
|---- Dockerfile
|---- ToInstall
      |---- rpm_1.rpm
      |---- rpm_2.rpm

Now you can run the command in the Docker file:

RUN rpm -i /ToInstall/rpm_1.rpm
0
source

Source: https://habr.com/ru/post/1545273/


All Articles