Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker VOLUME command inside Dockerfile not working as expected

FROM ubuntu:15.04
RUN mkdir -p /app/tina
RUN touch /app/tina/foo.txt
RUN echo "testing tina" > /app/tina/foo.txt
VOLUME /app/tina
CMD sh

As per Docker guide

This Dockerfile results in an image that causes docker run to create a new mount point at /app/tina and copy the foo.txt file into the newly created volume

but when I do

docker run --rm -it -v /tmp/foo:/app/tina imagename sh
ls /app/tina/

I can't find foo.txt inside it.

like image 815
Mr Coder Avatar asked Mar 09 '26 16:03

Mr Coder


1 Answers

From https://docs.docker.com/engine/reference/builder/#volume

The VOLUME instruction creates a mount point with the specified name and marks it as holding externally mounted volumes from native host or other containers.

You are using /tmp/foo which is a directory, not a volume. Try:

docker volume create my-vol
docker run --rm -it -v my-vol:/app/tina imagename ls /app/tina/
like image 194
vladmihaisima Avatar answered Mar 12 '26 09:03

vladmihaisima



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!