构建Docker映像期间无法访问卷

时间:2018-08-01 07:14:05

标签: docker build dockerfile docker-volume

我正在尝试创建一个名为“ 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

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

1 个答案:

答案 0 :(得分:1)

对不起,我刚刚发现在构建期间无法访问卷。它们在容器运行期间可以访问,即here in the point 9。但是当我将Dockerfile更改为此:

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

...效果很好,并打印了示例文件夹中的所有文件。

相关问题