2017-01-16 37 views
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。

回答

1

通常,您不需要它們,直到您想要更改主機上的代碼並查看Docker容器上的更改爲止。

你的設置看起來不錯,所有你需要的是定義諸如

構建您的構建方面: 方面:./nginx-proxy

其他然後,你的COPY語句將內容複製權像你期待在構建期間,所以不需要在運行時使用卷(除了頂部列出的同步情況)

+0

謝謝!這是否意味着整個問題出現在這個「背景」關鍵詞中?如果我添加並刪除卷,它是否會以沒有上下文和卷的相同方式工作? – Jacobian

+0

對,應該是這樣。從概念上說,你做了/認爲恰到好處 –

+0

謝謝!我會在一分鐘內檢查它! – Jacobian