Docker volume map files


I need some help with docker volumes.

  1. How do I map a volume to a specific directory on my machine (for instance my home directory).
    It seems that I can only use the default location for volumes in /var/lib/docker/volumes/ ?

  2. How do I map only specific files in a directory?
    For instance

    docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/config/mosquitto.conf eclipse-mosquitto

This command fails because mosquitto.conf is seen as a directory and not a file?

Thank you.


In your volume mapping, you use a name and not a path. If only a name is given, it will be interpreted as named volume, which can not be a single file.

You need to use a bind volume: -v /path/to/your/mosquitto.conf:/mosquitto/config/mosquitto.conf

It’s a pitty that configs and secrets are only available for swarm services. With swarm services they allow to mount single files read-only into containers.