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.

1 Like

Ok I think I understand, however I can see the /mnt after the image build… there appears to be data in it but the directory is empty. I also can’t make a sub-directory in /mnt within the image. That is:

cd /mnt
mkdir test

There is nothing in /mnt.

However, if i run the container in -it mkdir test works. Thank you :slight_smile:

To add a bit more context during the image build I cd to /mnt and execute aws sync… I can see the files being synced but /mnt is empty inside the container.
Outside of the container I can see them… that is ls /mnt returns the expected results. I guess during the image build /mnt is not accessible or is there a better way?