在构建 docker 映像期间无法访问卷
Can't access a volume during building a docker image
我正在尝试创建一个 docker 容器,其中包含一个名为 'example' 的卷,其中包含一些文件,但我无法在构建过程中访问它。以下是我正在使用的文件:
# 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 中删除 运行 命令并再次 运行 sudo docker-compose up
,然后 运行:
docker exec -it c949eef14fcd /bin/bash # c949eef14fcd is the id of the created container
ls /var/example
...在另一个终端window,没有报错,可以看到example目录下的所有文件。为什么?
抱歉,我刚刚发现在构建期间无法访问卷。在容器 运行 期间可以访问它们,即 here in the point 9。但是当我将 Dockerfile 更改为:
# Dockerfile
FROM ubuntu:14.04
CMD ["ls", "/var/example"]
...它运行良好并打印出示例文件夹中的所有文件。
我正在尝试创建一个 docker 容器,其中包含一个名为 'example' 的卷,其中包含一些文件,但我无法在构建过程中访问它。以下是我正在使用的文件:
# 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 中删除 运行 命令并再次 运行 sudo docker-compose up
,然后 运行:
docker exec -it c949eef14fcd /bin/bash # c949eef14fcd is the id of the created container
ls /var/example
...在另一个终端window,没有报错,可以看到example目录下的所有文件。为什么?
抱歉,我刚刚发现在构建期间无法访问卷。在容器 运行 期间可以访问它们,即 here in the point 9。但是当我将 Dockerfile 更改为:
# Dockerfile
FROM ubuntu:14.04
CMD ["ls", "/var/example"]
...它运行良好并打印出示例文件夹中的所有文件。