Docker 命名卷未更新
Docker named volume not updating
我对应该如何使用指定的数据卷(而不是数据容器)感到困惑。
我有一个命名数据卷 app_src
,它使用 docker 组合文件安装到 /usr/src/app
。但是,在对我的源代码(本地)进行更改后,构建图像不会更新音量。
我正在构建图像,
docker-compose -f development.yml build
和 运行 它 docker-compose -f development.yml up -d
.
为了确认卷没有变化,我附加到 运行 容器中,确实如此,源代码没有更新。
这是我的 docker 组合文件 development.yml
和 Dockerfile
用于我的 web
服务。
版本:'2'
services:
web:
restart: always
build: ./web
expose:
- "8000"
volumes:
- app_src:/usr/src/app
links:
- postgres:postgres
env_file: development.env
command: ./start_web.sh
volumes:
app_src: {}
FROM python:3.4.4
WORKDIR /usr/src/app
RUN rm -rf /usr/src/app/*
COPY . /usr/src/app/
RUN pip install --no-cache-dir -r requirements.txt
我可以像这样挂载主机让它工作,
volumes:
- ./web/src:/usr/src/app
我在 Ubuntu 16.04 运行 docker 1.11.2。我的理解错了吗?我确实查看了文档,但我能找到任何能很好地解释该卷的内容。
您多次将卷装入同一位置。
第一次容器将数据存储到主机文件系统中,第二次它覆盖主机文件系统中的数据 INTO 容器。
从你身上移除卷挂载 docker-撰写文件
volumes:
- ./web/src:/usr/src/app #remove this!
您可以获得更多信息here
$ docker run -d -P --name web -v /src/webapp:/opt/webapp training/webapp python app.py
This command mounts the host directory, /src/webapp, into the container at /opt/webapp. If the path /opt/webapp already exists inside the container’s image, the /src/webapp mount overlays but does not remove the pre-existing content. Once the mount is removed, the content is accessible again. This is consistent with the expected behavior of the mount command.
您似乎在尝试使用 docker-compose 与命名卷装载和 Dockerfile 来修改该位置的内容。这不会起作用,因为 Dockerfile 正在创建图像。 docker-compose 正在定义 运行ning 容器,该容器 运行 位于该图像之上。您将无法在映像创建过程中修改卷,因为该卷仅在映像创建后安装,您 运行 容器。
如果你想更新你的命名卷,考虑一个侧容器:
docker run -v app_src:/target -v `pwd`/web/src:/source --rm \
busybox /bin/sh -c "tar -cC /source . | tar -xC /target"
您可以 运行 该容器按需更新您的命名卷。您还可以将 tar 替换为 git clone
之类的内容以从源存储库中拉取,甚至是 rsync (您需要在图像上安装它)如果您对大的文件进行小的更改存储库。
您也可以通过清空指定卷(rm -rf /vol/dir 或删除卷并创建一个新卷)然后重新tar 容器来解决此问题。在容器的 startup 上,如果包含一个空的命名卷,默认是将该位置的图像内容复制到该卷中。
解决方法是重新创建卷,当然,如果您可以承受更长的停机时间:
docker-compose down && docker volume rm <VOLUME_NAME> && docker-compose up -d
我对应该如何使用指定的数据卷(而不是数据容器)感到困惑。
我有一个命名数据卷 app_src
,它使用 docker 组合文件安装到 /usr/src/app
。但是,在对我的源代码(本地)进行更改后,构建图像不会更新音量。
我正在构建图像,
docker-compose -f development.yml build
和 运行 它 docker-compose -f development.yml up -d
.
为了确认卷没有变化,我附加到 运行 容器中,确实如此,源代码没有更新。
这是我的 docker 组合文件 development.yml
和 Dockerfile
用于我的 web
服务。
版本:'2'
services:
web:
restart: always
build: ./web
expose:
- "8000"
volumes:
- app_src:/usr/src/app
links:
- postgres:postgres
env_file: development.env
command: ./start_web.sh
volumes:
app_src: {}
FROM python:3.4.4
WORKDIR /usr/src/app
RUN rm -rf /usr/src/app/*
COPY . /usr/src/app/
RUN pip install --no-cache-dir -r requirements.txt
我可以像这样挂载主机让它工作,
volumes:
- ./web/src:/usr/src/app
我在 Ubuntu 16.04 运行 docker 1.11.2。我的理解错了吗?我确实查看了文档,但我能找到任何能很好地解释该卷的内容。
您多次将卷装入同一位置。 第一次容器将数据存储到主机文件系统中,第二次它覆盖主机文件系统中的数据 INTO 容器。 从你身上移除卷挂载 docker-撰写文件
volumes:
- ./web/src:/usr/src/app #remove this!
您可以获得更多信息here
$ docker run -d -P --name web -v /src/webapp:/opt/webapp training/webapp python app.py
This command mounts the host directory, /src/webapp, into the container at /opt/webapp. If the path /opt/webapp already exists inside the container’s image, the /src/webapp mount overlays but does not remove the pre-existing content. Once the mount is removed, the content is accessible again. This is consistent with the expected behavior of the mount command.
您似乎在尝试使用 docker-compose 与命名卷装载和 Dockerfile 来修改该位置的内容。这不会起作用,因为 Dockerfile 正在创建图像。 docker-compose 正在定义 运行ning 容器,该容器 运行 位于该图像之上。您将无法在映像创建过程中修改卷,因为该卷仅在映像创建后安装,您 运行 容器。
如果你想更新你的命名卷,考虑一个侧容器:
docker run -v app_src:/target -v `pwd`/web/src:/source --rm \
busybox /bin/sh -c "tar -cC /source . | tar -xC /target"
您可以 运行 该容器按需更新您的命名卷。您还可以将 tar 替换为 git clone
之类的内容以从源存储库中拉取,甚至是 rsync (您需要在图像上安装它)如果您对大的文件进行小的更改存储库。
您也可以通过清空指定卷(rm -rf /vol/dir 或删除卷并创建一个新卷)然后重新tar 容器来解决此问题。在容器的 startup 上,如果包含一个空的命名卷,默认是将该位置的图像内容复制到该卷中。
解决方法是重新创建卷,当然,如果您可以承受更长的停机时间:
docker-compose down && docker volume rm <VOLUME_NAME> && docker-compose up -d