【发布时间】:2020-12-12 16:33:04
【问题描述】:
在阅读了 volumes 上的 docker 文档以及如何在 docker-compose 中使用它们之后,我相信这个最小的示例可以将本地目录挂载为卷:
docky/Dockerfile
FROM alpine
ENTRYPOINT ["ash"]
docky/docker-compose.yml
version: '3'
services:
server:
build:
context: .
dockerfile: Dockerfile
volumes:
- ./bindme:/bound
但是卷没有挂载:
$ docker-compose build
Building server
Step 1/2 : FROM alpine
---> b14afc6dfb98
Step 2/2 : ENTRYPOINT ["ash"]
---> Using cache
---> 68fcd94074c9
Successfully built 68fcd94074c9
Successfully tagged docky_server:latest
$ docker run -it 68fcd94074c9
/ # ls /bound
ls: /bound: No such file or directory
$ docker inspect 68fcd94074c9 | grep -e Volumes -e Binds -e Mounts
"Volumes": null,
"Volumes": null,
目录./bindme 存在并包含一个文件。我错过了什么/做错了什么?
- Docker 版本 20.10.0,构建 7287ab3
- docker-compose 版本 1.25.0
【问题讨论】:
-
Docker 构建不会以任何方式包含挂载。您需要使用 compose 以及
docker-compose up启动 docker 容器。 -
使用
up,inspect 显示正确的绑定安装条目,并且还在Volumes中显示"/bound": {};但是/bound在容器中仍然不存在
标签: docker docker-compose