docker - 我的 docker-compose.yml 文件应该如何将 HAProxy 与 Heroku 和 Docker 一起使用?
问题描述
我试图关注这篇文章,但现在很多事情看起来都不一样了,所以我最终即兴创作。我想简单地将前端与后端连接起来,避免 CORS 头痛(尽管现在我不确定哪个头痛更大)。无论如何,我以这种方式定义了我的负载均衡器:
应用程序.json:
{
"name": "NeuroCore Load Balancer",
"description": "A load balancer for NeuroCore"
}
档案:
web: sbin/haproxy -f haproxy.cfg
Dockerfile:
FROM heroku/heroku:18
RUN mkdir -p /app/user
WORKDIR /app/user
# Install HAProxy
RUN apt-get update && apt-get install -y libssl1.0.0 libpcre3 --no-install-recommends && rm -rf /var/lib/apt/lists/*
ENV HAPROXY_MAJOR 1.5
ENV HAPROXY_VERSION 1.5.14
ENV HAPROXY_MD5 ad9d7262b96ba85a0f8c6acc6cb9edde
# see http://sources.debian.net/src/haproxy/1.5.8-1/debian/rules/ for some helpful navigation of the possible "make" arguments
RUN buildDeps='curl gcc libc6-dev libpcre3-dev libssl-dev make' \
&& set -x \
&& apt-get update && apt-get install -y $buildDeps --no-install-recommends && rm -rf /var/lib/apt/lists/* \
&& curl -SL "http://www.haproxy.org/download/${HAPROXY_MAJOR}/src/haproxy-${HAPROXY_VERSION}.tar.gz" -o haproxy.tar.gz \
&& echo "${HAPROXY_MD5} haproxy.tar.gz" | md5sum -c \
&& mkdir -p /app/user/src/haproxy \
&& tar -xzf haproxy.tar.gz -C /app/user/src/haproxy --strip-components=1 \
&& rm haproxy.tar.gz \
&& make -C /app/user/src/haproxy \
TARGET=linux2628 \
USE_PCRE=1 PCREDIR= \
USE_OPENSSL=1 \
USE_ZLIB=1 \
PREFIX=/app/user \
all \
install-bin \
&& rm -rf /app/user/src/haproxy \
&& apt-get purge -y --auto-remove $buildDeps
COPY haproxy.cfg /app/user/haproxy.cfg
haproxy.cfg:
global
maxconn 256
defaults
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
frontend http
bind 0.0.0.0:$PORT
option forwardfor
# Force SSL
redirect scheme https code 301 if ! { hdr(x-forwarded-proto) https }
# And all other requests to `example-com`.
default_backend neurocore-backend
backend neurocore-backend
http-request set-header X-Forwarded-Host neurocore.herokuapp.com
http-request set-header X-Forwarded-Port %[dst_port]
reqirep ^Host: Host:\ neurocore-backend.herokuapp.com
server backend neurocore-backend.herokuapp.com:443 ssl verify none
运行后docker-compose up web
我得到:
ERROR: Can't find a suitable configuration file in this directory or any parent. Are you in the right directory? Supported filenames: docker-compose.yml, docker-compose.yaml
据我了解,这个文件应该是由heroku docker:init
命令生成的,但现在它不起作用。那么,我应该怎么做才能让我的应用程序启动并运行呢?
解决方案
推荐阅读
- grep - Grep 查找以 " 后跟 10 位数字 ","" 开头的行
- jsp - 如何编码此 jsp 行。需要从 xss 扫描中清除
- ruby-on-rails - 如何在 Minitest 中模拟一系列方法
- python - Why does shuffling array 'A' also shuffle array 'B', but updating int 'a' doesn't update int 'b'?
- linux - 将我的 bash 脚本的输出存储在 .txt 文件中
- python - 使用 pandas 比较两列并更新更改的值并附加缺失值
- python - 带有过滤器的 Google Analytics API 事件跟踪
- oracle - oracle 中的合并查询抛出“ORA-01652:无法在表空间 TEMP 中将临时段扩展 64”
- swift - 计时问题:节拍器使用 AVAudioEngine scheduleBuffer 的完成处理程序
- python - 如何将按钮连接到使用 pyqt 在 python 中保存新条目的数据库?