Docker-撰写无法复制haproxy.cfg
Docker-Compose not able to copy haproxy.cfg
我的问题是我有一个 docker-compose.yml
文件和一个 haproxy.cfg
文件,我希望 docker-compose 将 haproxy.cfg
文件复制到 docker 容器。根据 post 我可以使用卷来做到这一点,但在我的情况下,我收到以下错误。谁能帮我实现这个。
下面是代码和所有内容
docker-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"
文件夹结构
命令输出
root@ubuntu:/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
为了向容器中添加其他文件,您必须在 haproxy 中的现有映像之上进行构建。
例如,您的 Dockerfile 应如下所示:
FROM haproxy:latest
COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
然后您可以相应地更新 docker 撰写文件。
如果您打算将其用于本地开发,只需挂载文件,请参阅@MatTheWhale 的回答
查看更多
试试这个:
volumes:
- ./haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
这不会挂载整个目录,而只会挂载 haproxy.cfg
。 ro
是read-only的缩写,使用它保证容器挂载后不会修改。
我的问题是我有一个 docker-compose.yml
文件和一个 haproxy.cfg
文件,我希望 docker-compose 将 haproxy.cfg
文件复制到 docker 容器。根据 post
下面是代码和所有内容
docker-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"
文件夹结构
命令输出
root@ubuntu:/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
为了向容器中添加其他文件,您必须在 haproxy 中的现有映像之上进行构建。
例如,您的 Dockerfile 应如下所示:
FROM haproxy:latest
COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
然后您可以相应地更新 docker 撰写文件。
如果您打算将其用于本地开发,只需挂载文件,请参阅@MatTheWhale 的回答
查看更多试试这个:
volumes:
- ./haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
这不会挂载整个目录,而只会挂载 haproxy.cfg
。 ro
是read-only的缩写,使用它保证容器挂载后不会修改。