docker-compose容器B无法到达容器A

时间:2020-07-06 03:17:54

标签: proxy docker-compose grpc envoyproxy

我有一个ReactJs App作为客户端和一个后端。要联系后端,客户端使用Envoy作为gRPC的代理。拨打后端电话时,我有以下逻辑:

ReactJs-> Envoy->后端

如果我在本地运行我的特使代理,则它可以工作。这是我的YAML

envoy.yaml

static_resources:
  listeners:
    - name: listener_0
      address:
        socket_address: { address: 0.0.0.0, port_value: 9000 }
      filter_chains:
        - filters:
            - name: envoy.http_connection_manager
              config:
                codec_type: auto
                stat_prefix: ingress_http
                route_config:
                  name: local_route
                  virtual_hosts:
                  - name: local_service
                    domains: ["*"]
                    routes:
                    - match:
                        prefix: "/"
                      route:
                        cluster: api_interface
                        max_grpc_timeout: 2s
                    cors:
                      allow_origin_string_match:
                        - safe_regex:
                            google_re2: {}
                            regex: \*
                      allow_methods: GET, PUT, DELETE, POST, OPTIONS
                      allow_headers: keep-alive,user-agent,cache-control,content-type,content-transfer-encoding,custom-header-1,x-accept-content-transfer-encoding,x-accept-response-streaming,x-user-agent,x-grpc-web,grpc-timeout
                      max_age: "1728000"
                      expose_headers: custom-header-1,grpc-status,grpc-message
                http_filters:
                  - name: envoy.grpc_web
                  - name: envoy.cors
                  - name: envoy.router
  clusters:
    - name: api_interface
      connect_timeout: 0.25s
      type: logical_dns
      http2_protocol_options: {}
      lb_policy: round_robin
      hosts: [{ socket_address: { address: host.docker.internal, port_value: 9001 }}]

proxy.Dockerfile

# This configuration will build a Docker container containing
# an Envoy proxy that routes to Google.

FROM envoyproxy/envoy:v1.12.2
RUN apt-get update
COPY envoy.yaml /etc/envoy.yaml
CMD /usr/local/bin/envoy -c /etc/envoy.yaml

但是,当我尝试在运行时使用docker-compose up --build时,它说:

proxy:9000 / MyBackend.MyBackend / GetMessages:1

无法加载资源:net :: ERR_NAME_NOT_RESOLVED

app.Dockerfile

###############
### Stage 1 ###
### ReactJs ###
###############

# Setting FROM
FROM node:12 AS builder

# Setting workdir
WORKDIR /app

# Copy packages and then install
COPY package.json package-lock.json ./
RUN npm install

# Setting env
ENV PATH="./node_modules/.bin:$PATH"

# Copy srcs
COPY . ./

# Run npm run build command
RUN npm run build

###############
### Stage 2 ###
###  NGINX  ###
###############

# Setting FROM
FROM nginx:1.17-alpine

# Run apk + curl
RUN apk --no-cache add curl
RUN curl -L https://github.com/a8m/envsubst/releases/download/v1.1.0/envsubst-`uname -s`-`uname -m` -o envsubst && \
    chmod +x envsubst && \
    mv envsubst /usr/local/bin

# Copying nginx config
COPY ./nginx.config /etc/nginx/nginx.template

# Run CMD command
CMD ["/bin/sh", "-c", "envsubst < /etc/nginx/nginx.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"]

# Copy build file to current image
COPY --from=builder /app/build /usr/share/nginx/html

docker-compose.yaml

version: '3.7'

services:
  proxy:
    build:
      context: .
      dockerfile: proxy.Dockerfile
    ports:
      - '9000:9000'
  backoffice-webapp:
    build:
      context: .
      dockerfile: app.Dockerfile
    depends_on:
      - proxy
    links:
      - "proxy:proxy"
    ports:
      - '80:80'

有什么主意吗?我想到了一个事实,我正在尝试达到host.docker.internal,也许与docker-compose不同。目前,它需要先在本地工作,然后才能进行远程工作(出于测试/开发目的)

阅读该文档,它说我应该能够联系http://proxy:9000(通过构建/运行代理来在没有docker compose的情况下进行测试。Dockerfile,我使用的http://localhost:9000就像一个超级按钮一样工作)(代理重定向到host.docker.internal,我的gRPC API在此监听:9001)

0 个答案:

没有答案