【问题标题】:Can't access a volume during building a docker image在构建 docker 映像期间无法访问卷
【发布时间】:2018-08-01 07:14:05
【问题描述】:

我正在尝试创建一个带有名为“example”的卷的 docker 容器,其中包含一些文件,但在构建期间我无法访问它。以下是我正在使用的文件:

# docker-compose.yml
version: "3"
services:
  example:
    build: .
    volumes:
      - "./example:/var/example"
    stdin_open: true
    tty: true

还有:

# Dockerfile
FROM ubuntu
RUN ls /var/example
CMD ["/bin/bash"]

当我跑步时:

sudo docker-compose up

它给了我一个错误:

ls: cannot access /var/example: No such file or directory

但是当我从 Dockerfile 中删除 RUN 命令并再次运行sudo docker-compose up,然后运行:

docker exec -it c949eef14fcd /bin/bash # c949eef14fcd is the id of the created container
ls /var/example

...在另一个终端窗口中,没有错误,我可以看到示例目录的所有文件。为什么?

【问题讨论】:

    标签: docker build dockerfile docker-volume


    【解决方案1】:

    抱歉,我刚刚发现在构建期间无法访问卷。它们可以在容器运行期间访问,即here in the point 9。但是当我把我的 Dockerfile 改成这样时:

    # Dockerfile
    FROM ubuntu:14.04
    CMD ["ls", "/var/example"]
    

    ...它运行得非常好,并打印出了示例文件夹中的所有文件。

    【讨论】:

      猜你喜欢
      • 2021-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-17
      • 1970-01-01
      • 2020-03-23
      • 1970-01-01
      相关资源
      最近更新 更多