我的本地文件夹如下所示:
docker-compose.yml
\nginx-proxy
\code
index.html
nginx.conf
Dockerfile
index.html
包含纯HTML代码。nginx.conf
包含以下简单配置:
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容器上查看更改。
您的设置看起来不错,您所需要的只是定义您的构建上下文,例如
构建:上下文:./ nginx-proxy
除此之外,您的COPY语句将复制内容,就像您在构建时所期望的那样,因此无需在运行时为此使用卷(顶部概述的同步情况除外)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句