2019.9.4 wisdom weather:rainy
ARG 和ENV的区别:
工作时机的不同:ARG是build的时候存在的,可以在dockerfile中当变量使用
ENV是容器构建好之后的环境变量,不能在dockerfile中当参数使用
ARG是为了专门构建镜像而生的
Volumes: 将宿主机中的目录路径和容器中的路径挂载
Manage Data in Docker
1.The data doesn't persist when the container no longer exists, and it can be difficult to get data out of the container if another process needs it
Docker has two options for containers to store files in the host machine, so that the files are persisted even after the container stops:
1)Volumes
2)bind mounts
3)if you running Docker on Linux :also can use tmpfs mount
what is the difference Volumes 、Bind mounts、tmpfs
Volumes are store in a part of the host filename which is managed by Docker (/var/lib/docker/volumes/ on linux)
Non-Docker process should not modify this part of the filename.Volume is the best way to persist data in Docker
Bind mounts: may be store anywhere on the host system.They may even be important system files or directories.
Non-Docker process on the docker host or a Docker container can modify them at any time.
tmpfs mounts are stored in the host systems's memory only,and are never written to the host system's filesystem.
docker volume create comand
Note: if you are developing new Docker applications,Consider using named volumes instead. you can not use docker CLI commands to directly manager bind mounts.
Bind mounts and volumes or tmpfs into container user --mount in Docker 17.06 and higher.
below Docker 17.o6
Bind mounts and volumes use -v
Bind tmpfs use --tmpfs
The docker service create command does not support the -v or --volume flag.
When mounting a volume into a service’s containers, you must use the --mount flag.
dockermore information :https://docs.docker.com/storage/
网友评论