2017-08-08 111 views
1

我的問題是我有一個docker-compose.yml文件和一個haproxy.cfg文件,我想docker-compose將haproxy.cfg文件複製到docker容器中。根據帖子Docker composer copy files我可以使用捲來做到這一點,但在我的情況下,我得到了以下錯誤。任何人都可以幫助我實現這一點。Docker-Compose不能複製haproxy.cfg

下面是代碼,一切

泊塢窗,compose.yml

version: "3.3" 
services: 
###After all services are up, we are initializing the gateway 
gateway: 
    container_name: gateway-haproxy 
    image: haproxy 
    volumes: 
    - .:/usr/local/etc/haproxy 
    ports: 
    - 80:80 
    network_mode: "host" 

文件夾結構

enter image description here

命令輸出

[email protected]:/home/karunesh/Desktop/Stuff/SelfStudy/DevOps/docker# docker-compose up 
Creating gateway-haproxy ... 
Creating gateway-haproxy ... done 
Attaching to gateway-haproxy 
gateway-haproxy | <7>haproxy-systemd-wrapper: executing /usr/local/sbin/haproxy -p /run/haproxy.pid -f /usr/local/etc/haproxy/haproxy.cfg -Ds 
gateway-haproxy | [ALERT] 219/163305 (6) : [/usr/local/sbin/haproxy.main()] No enabled listener found (check for 'bind' directives) ! Exiting. 
gateway-haproxy | <5>haproxy-systemd-wrapper: exit, haproxy RC=1 
gateway-haproxy exited with code 1 
+0

你不能用docker-compose將一個文件複製到一個容器中。這必須在'Dockerfile'本身完成 – Serey

+0

我沒有文件...我應該使用官方haproxy圖像...有什麼辦法可以做到這一點... – utkarsh31

+0

@Serey我已經完成它之前,看到我的答案 – MatTheWhale

回答

3

試試這個:

volumes: 
    - ./haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro 

相反掛載整個目錄,這隻會掛載haproxy.cfgro是隻讀的縮寫,其用法保證容器在掛載後不會對其進行修改。

+0

感謝很多墊....工作.. :) – utkarsh31

1

爲了向容器添加其他文件,您必須在haproxy的現有圖像之上構建。

例如,您Dockerfile應該是這樣的:

FROM haproxy:latest 
COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg 

然後你就可以相應地更新您的碼頭工人撰寫的文件。

如果你打算使用這個地方發展,只是安裝文件(S),見@ MatTheWhale的答案

多見於official haproxy Docker page

+0

非常感謝這個......但無論如何,我們可以在不使用docker文件的情況下做到這一點......讓我們假設我有Docker鏡像,並且在'haproxy.cfg'中做了一些更改。而不是更新圖像可以不直接複製本地'haproxy.cfg'到圖像中的位置... – utkarsh31

+0

謝謝serey ... – utkarsh31