0
我的本地文件夾看起來像這樣:爲什麼我必須要使用卷指令泊塢窗,構成
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),但是,如果我sl ightly改變搬運工,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
說明?我希望我可以在COPY指令中使用我的Dockerfile。
謝謝!這是否意味着整個問題出現在這個「背景」關鍵詞中?如果我添加並刪除卷,它是否會以沒有上下文和卷的相同方式工作? – Jacobian
對,應該是這樣。從概念上說,你做了/認爲恰到好處 –
謝謝!我會在一分鐘內檢查它! – Jacobian