理解“音量"DockerFile 中的指令 [英] Understanding "VOLUME" instruction in DockerFile

查看:25
本文介绍了理解“音量"DockerFile 中的指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的Dockerfile"的内容

Below is the content of my "Dockerfile"

FROM node:boron

# Create app directory
RUN mkdir -p /usr/src/app

# Change working dir to /usr/src/app
WORKDIR /usr/src/app

VOLUME . /usr/src/app

RUN npm install

EXPOSE 8080

CMD ["node" , "server" ]

在这个文件中,我期待 VOLUME ./usr/src/app 挂载指令要挂载在 /usr/src/app 上的主机中当前工作目录的内容容器文件夹.

In this file I am expecting VOLUME . /usr/src/app instruction to mount contents of present working directory in host to be mounted on /usr/src/app folder of container.

请告诉我这是否正确?

推荐答案

docker 官方教程说:

The official docker tutorial says:

数据卷是绕过联合文件系统的一个或多个容器中专门指定的目录.数据卷为持久或共享数据提供了几个有用的功能:

A data volume is a specially-designated directory within one or more containers that bypasses the Union File System. Data volumes provide several useful features for persistent or shared data:

  • 在创建容器时初始化卷.如果容器的基础镜像包含指定挂载点的数据,
    现有数据按卷复制到新卷中
    初始化.(请注意,这在挂载主机时不适用
    目录.)

  • Volumes are initialized when a container is created. If the container’s base image contains data at the specified mount point,
    that existing data is copied into the new volume upon volume
    initialization. (Note that this does not apply when mounting a host
    directory.)

数据卷可以在容器之间共享和重复使用.

Data volumes can be shared and reused among containers.

直接更改数据量.

更新图像时不会包括对数据卷的更改.

Changes to a data volume will not be included when you update an image.

即使容器本身被删除,数据卷仍然存在.

Data volumes persist even if the container itself is deleted.

Dockerfile中,您只能指定容器内卷的目的地.例如/usr/src/app.

In Dockerfile you can specify only the destination of a volume inside a container. e.g. /usr/src/app.

当你运行一个容器时,例如docker run --volume=/opt:/usr/src/app my_image,你可以但不必指定它的安装点(/opt) 在主机上.如果不指定 --volume 参数,则挂载点将自动选择,通常在 /var/lib/docker/volumes/ 下.

When you run a container, e.g. docker run --volume=/opt:/usr/src/app my_image, you may but do not have to specify its mounting point (/opt) on the host machine. If you do not specify --volume argument then the mount point will be chosen automatically, usually under /var/lib/docker/volumes/.

这篇关于理解“音量"DockerFile 中的指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆