Home >Operation and Maintenance >Docker >What is the difference between -v and -mount in docker
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.
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: dockerdocker run --name $CONTAINER_NAME -it \ -v $PWD/$CONTAINER_NAME/app:/app:rw \ -v $PWD/$CONTAINER_NAME/data:/data:ro \ avocado-cloud:latest /bin/bashComment: SecurityCommand 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: bashdocker 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/bashComment: appMount 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 existIn the example, readonly means read-onlyDifference: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!