Home  >  Article  >  Operation and Maintenance  >  What is the difference between -v and -mount in docker

What is the difference between -v and -mount in docker

WBOY
WBOYOriginal
2021-12-29 11:50:0513073browse

The difference between "-v" and "-mount" in docker is: when using "-v" to mount the host directory, if there is no specified file on the host, no error will be reported, and the specified file will be automatically created; when When using "-mount", if there is no such file in the host, an error will be reported and the specified file cannot be found, and the specified file will not be automatically created.

What is the difference between -v and -mount in docker

The operating environment of this tutorial: linux7.3 system, docker-1.13.1 version, Dell G3 computer.

What is the difference between -v and -mount in docker

##--volume(-v)

The parameter --volume (or -v for short) can only create a bind mount. Example: docker

docker run --name $CONTAINER_NAME -it \
-v $PWD/$CONTAINER_NAME/app:/app:rw \
-v $PWD/$CONTAINER_NAME/data:/data:ro \
avocado-cloud:latest /bin/bash

Comment: Security

Command format: [[HOST-DIR:]CONTAINER-DIR[:OPTIONS]]]

If HOST-DIR is specified, then It must be an absolute path. If the path does not exist, it will be created automatically.

The rw in the instance is read-write, and the ro is read-only

--mount

Parameter --mount is used to mount volume by default, but can also be used to create bind mount and tmpfs. If the type option is not specified, the default is to mount volume. Volume is a more flexible data management method. Volume can be managed through the docker volume command set. Example: bash

docker run --name $CONTAINER_NAME -it \
--mount type=bind,source=$PWD/$CONTAINER_NAME/app,destination=/app \
--mount source=${CONTAINER_NAME}-data,destination=/data,readonly \
avocado-cloud:latest /bin/bash

Comment: app

Mount volume command format: [type=volume,]source=my-volume,destination=/path/in/container[,... ]

Create bind mount command format: type=bind,source=/path/on/host,destination=/path/in/container[,...]

If you create bind mount And specifying source must be an absolute path, and the path must already exist

In the example, readonly means read-only

Difference:

When using -v, if there is no This file will also be created automatically,

However, if --mount is used, if there is no such file in the host machine, an error will be reported that the file cannot be found, and the creation will fail.

Recommended study: "

docker video tutorial

The above is the detailed content of What is the difference between -v and -mount in docker. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn