【发布时间】: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