Docker-Compose无法复制haproxy.cfg [英] Docker-Compose not able to copy haproxy.cfg

查看:337
本文介绍了Docker-Compose无法复制haproxy.cfg的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是我有一个docker-compose.yml文件和一个haproxy.cfg文件,我想让docker-compose将haproxy.cfg文件复制到docker容器中.根据 Docker composer复制文件的帖子,我可以使用卷来做,但是就我而言正在收到以下错误.谁能帮我实现这一目标.

My problem is that I have a docker-compose.yml file and an haproxy.cfg file and I want docker-compose to copy the haproxy.cfg file to the docker container. As per the post Docker composer copy files I can use volumes to do it but in my case I'm getting the below error. Can anybody help me achieve this.

下面是代码和所有内容

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

推荐答案

尝试一下:

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

仅装载haproxy.cfg,而不是装载整个目录. ro是只读的缩写,它的用法可确保容器在挂载后不会对其进行修改.

Instead of mounting the whole directory, this will only mount haproxy.cfg. The ro is an abbreviation for read-only, and its usage guarantees the container won't modify it after it gets mounted.

这篇关于Docker-Compose无法复制haproxy.cfg的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆