Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using volume for mounting a file

Tags:

docker

I'm creating a volume like this:

docker volume create php

and want to mount a single file /etc/php.ini while running the container:

docker run -it -v php:/etc/php.ini image-name

This throws an error:

docker: Error response from daemon: readdirent: not a directory.
See 'docker run --help'.

Can I use volumes for this purpose or they are meant to handle directories only? What could be the solution here?

like image 452
revo Avatar asked Nov 28 '25 03:11

revo


1 Answers

According to this answer:

when you create a named volume and run a service/container with docker run -v my_volume:/root/volume my_container, data is stored in /var/lib/docker/volumes/my_volume/_data

Following this affirmation, it is unpossible to create a named volume and mount it as a file inside a container.

like image 158
gcharbon Avatar answered Nov 29 '25 21:11

gcharbon



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!