Docker supports mounting a directory on a host to an image.
docker run -it -v /home/dock/Downloads:/usr/Downloads ubuntu64 /bin/bash
The-V parameter indicates that the directory of the host machine is prefixed with the colon, which must be an absolute path and the path mounted in the image after the colon.
Now, files in the host can be shared in the image.
The default Mount path permission is read/write. If it is specified as read-only, you can use: RO
docker run -it -v /home/dock/Downloads:/usr/Downloads:ro ubuntu64 /bin/bash
Docker also provides an advanced usage. It is called a data volume.
Data volumes: "They are actually a normal container dedicated to providing data volumes for other containers to mount ". It seems like a data mount information defined by a container. Other containers can be started to directly mount the mounting information defined in the data volume container.
Example:
docker run -v /home/dock/Downloads:/usr/Downloads --name dataVol ubuntu64 /bin/bash
Create a common container. Use -- name to specify a name (if not specified, a random name is generated ).
Create a new container to use the data volume.
docker run -it --volumes-from dataVol ubuntu64 /bin/bash
-- Volumes-from is used to specify the volume from which data is to be mounted.
Docker learning --- mount a local directory