为什么我必须在docker-compose中使用卷指令
我的本地文件夹如下所示:
docker-compose.yml \nginx-proxy \code index.html nginx.conf Dockerfile
index.html
包含纯html代码。 nginx.conf
包含这个简单的configuration:
worker_processes 1; events { worker_connections 1024; } http { sendfile on; server { listent 80; root /code; index index.html; } }
Dockerfile
包含这些说明:
FROM nginx:latest COPY nginx.conf /etc/nginx/nginx.conf COPY ./code /code
最后docker-compose
包含这些说明:
nginx: build: ./nginx-proxy container_name: nginx-proxy ports: - "8181:80"
当我运行docker-compose up
并转到localhost:8181
出于某种原因,我看到一个欢迎的nginx页面(不是我的index.html),但是,如果,我稍微更改docker-compose.yml:
nginx: build: ./nginx-proxy container_name: nginx-proxy ports: - "8181:80" volumes: - ./nginx-proxy/code:/code - ./nginx-proxy/nginx.conf:/etc/nginx/nginx.conf
所以,我的问题是为什么我必须指定这个volumes
指示? 我希望我可以使用我的Dockerfile COPY指令。
一般来说,你不需要它们,直到你想要改变主机上的代码,并看到docker集装箱上的变化。
你的设置看起来不错,你需要的只是定义你的构build上下文
build:context:./nginx-proxy
除此之外,您的COPY语句将像构build时期期望的那样正确地复制内容,因此在运行时不需要使用卷(除了顶部列出的同步情况外)
- 具有泊坞窗图像的远程服务器如何知道何时拉出使用CI工具构build的新图像?
- 在编译Docker Alpine中的qpid-cpp时如何解决`构buildCXX对象src / CMakeFiles / qpidcommon.dir / qpid / sys / posix / Condition.cpp.o`?
- Spark JobServer没有运行我提交的工作
- 为什么Jupyter笔记本在docker张量图像上的atp-get更新之后没有启动?
- 如何在基于Docker的微服务中pipe理每个环境的数据?
- Docker容器的根PID
- 如何configurationDocker的mysql + aspnet
- Docker知道在何处从构buildDockerfile的地方拉取.sh脚本?
- docker images / json endpoint中“Containers”和“SharedSize”是什么意思?