Docker Community Forums

Share and learn in the Docker community.

Mountpoint in alpine image build

Is there a way to add a mount to an alpine image build? The below builds and I do see /mnt in the container, but I do not see the data within /mnt, that is the sub-directories in it. Thankyou :).

docker image build -t test .
FROM alpine:3.13.5

WORKDIR /path/to

VOLUME /mnt

You might want the check the VOLUME section in Dockerfile reference again.

This declaration does not actualy mount the host folder into the container. It just marks that it is expects a volume to be mapped into this folder when a container is created from this image. If you don’t map a volume when creating the folder, docker will create an anonymouns volume and map it into the folder (those are volumes with alpanumeric names when you execute docker volume ls).

Typicaly you use the COPY instruction to copy files from the build context into your build container during build time. Though, the files need to be available in the build context, which is the folder and its subfolders where the Dockerfile is stored. Make sure to declare a .dockerignore file that list all files you don’t want to be visible inside the build context.