Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to mount a directory while building from Dockerfile?

Tags:

docker

I'm trying to build a Docker image using the Dockerfile method. Minimizing the image size and number of layers is very important for this specific application. However, the rpm needed for installation is fairly large and I don't want to bake that into the image. It seems that if I use the ADD command in the Dockerfile, the rpm gets copied into the image as its own layer and there's no way to remove it after I'm done using it. To get around this, we're just running a container in interactive mode with the -v volume mounting option to share the folder containing the rpm, but not actually copying the rpm to the container. Is there any way to do something like the -v option while running the docker build command with Dockerfiles?

like image 476
user1777663 Avatar asked Oct 31 '22 21:10

user1777663


1 Answers

The method a co-worker came up with is to use docker run and 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

The install-script.sh would something like:

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

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

Ciao!

like image 70
docwhat Avatar answered Nov 09 '22 11:11

docwhat