了解“ VOLUME” DockerFile中的指令 [英] Understanding "VOLUME" instruction in DockerFile

查看:78
本文介绍了了解“ VOLUME” 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.

请告诉我这是否正确吗?

Please let me know if this is the correct way ?

推荐答案

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.)

可以共享数据卷,

直接更改数据量。

更新映像时将不包括对数据卷的更改。

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

即使容器本身已删除。

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/.

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

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