In Docker there are two ways you can mount volumes to the container.
- The first method is to directly use any of the host directory to map to a directory inside container.
- The second method is using a
data volume container. In this method the host directory is mounted to a container and we refer to this data volume container as the volume source to mount to our application container.
Just to give you a basic idea, consider the following scenario.
/opt/host/config is the directory on host
/opt/container/config is the directory inside the container where your app writes the json configuration
- Lets say you are using
Now to mount the host directory to container directory you can run the container as shown below.
docker run -it --rm -v /opt/host/config:/opt/container/config centos:6
Now you will be able to access the host directory at
Just a point to note is , if your app modifies the json file at runtime, you should not be mounting the same directory to multiple containers as each one modifying the config may result in issues, and this is purely dependent on the design of your app.
You should read this page to understand better. https://docs.docker.com/userguide/dockervolumes/