Docker learning --- mount a local directory

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.