Elastic Beanstalk 中的多个 Docker 容器上没有网络连接

Elastic Beanstalk 中的多个 Docker 容器上没有网络连接

我正在尝试将多个 docker 容器部署到 Elastic Beanstalk。有两个容器,一个用于 Supervisor+uwsgi+django 应用程序,另一个用于 JavaScript 前端。

使用 docker-compose 在本地运行良好

我的docker-compose文件:

version: '2'

services:
  frontend:
    image: node:latest
    working_dir: "/frontend"
    ports:
      - "3000:3000"
    volumes:
      - ./frontend:/frontend
      - static-content:/frontend/build
    command: bash -c "yarn install && yarn build"
  web:
    build: web/
    working_dir: "/app"
    volumes:
      - ./web/app:/app
      - static-content:/home/docker/volatile/static
    command: bash -c "pip3 install -r requirements.txt && python3 manage.py migrate && supervisord -n"
    ports:
      - "80:80"
      - "8000:8000"
    depends_on:
      - db
      - frontend
volumes:
  static-content:

nodejs 的镜像是官方的 Docker 镜像。对于“web”,我使用以下 Dockerfile:

FROM ubuntu:16.04

# Install required packages and remove the apt packages cache when done.
RUN apt-get update && \
    apt-get upgrade -y && \
    apt-get install -y \
    python3 \
    python3-dev \
    python3-setuptools \
    python3-pip \
    nginx \
    supervisor \
    sqlite3 && \
    pip3 install -U pip setuptools && \
   rm -rf /var/lib/apt/lists/*

# install uwsgi now because it takes a little while
RUN pip3 install uwsgi

# setup all the configfiles
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
COPY nginx-app.conf /etc/nginx/sites-available/default
COPY supervisor-app.conf /etc/supervisor/conf.d/

EXPOSE 80
EXPOSE 8000

但是,AWS 使用自己的“compose”设置,该设置定义在 dockerrun.aws.json 中,语法不同,因此我必须对其进行调整。首先,我使用了容器变换应用程序根据我的docker-compose生成文件

然后我必须做一些调整,即:AWS 文件似乎没有“workdir”属性,所以我不得不根据

我还将我的镜像发布到了 AWS Elastic Container Registry

文件变成如下形式:

{
  "AWSEBDockerrunVersion": 2,
  "containerDefinitions": [
      {
          "command": [
              "bash",
              "-c",
              "yarn install --cwd /frontend && yarn build --cwd /frontend"
          ],
          "essential": true,
          "image": "node:latest",
          "memory": 128,
          "mountPoints": [
              {
                  "containerPath": "/frontend",
                  "sourceVolume": "_Frontend"
              },
              {
                  "containerPath": "/frontend/build",
                  "sourceVolume": "Static-Content"
              }
          ],
          "name": "frontend",
          "portMappings": [
              {
                  "containerPort": 3000,
                  "hostPort": 3000
              }
          ]
      },
      {
          "command": [
              "bash",
              "-c",
              "pip3 install -r /app/requirements.txt && supervisord -n"
          ],
          "essential": true,
          "image": "<my-ecr-image-path>",
          "memory": 128,
          "mountPoints": [
              {
                  "containerPath": "/app",
                  "sourceVolume": "_WebApp"
              },
              {
                  "containerPath": "/home/docker/volatile/static",
                  "sourceVolume": "Static-Content"
              },
              {
                "containerPath": "/var/log/supervisor",
                "sourceVolume": "_SupervisorLog"
              }
          ],
          "name": "web",
          "portMappings": [
              {
                  "containerPort": 80,
                  "hostPort": 80
              },
              {
                  "containerPort": 8000,
                  "hostPort": 8000
              }
          ],
          "links": [
            "frontend"
          ]
      }
  ],
  "family": "",
  "volumes": [
      {
          "host": {
              "sourcePath": "/var/app/current/frontend"
          },
          "name": "_Frontend"
      },
      {
          "host": {
              "sourcePath": "static-content"
          },
          "name": "Static-Content"
      },
      {
          "host": {
              "sourcePath": "/var/app/current/web/app"
          },
          "name": "_WebApp"
      },
      {
        "host": {
            "sourcePath": "/var/log/supervisor"
        },
        "name": "_SupervisorLog"
    }
  ]
}

但部署后我在日志中看到它:

> -------------------------------------                                                                                                                                                                                              /var/log/containers/frontend-xxxxxx-stdouterr.log                     
> 
> -------------------------------------                                                                                                                                                                                              yarn install v1.3.2                                                   
> [1/4] Resolving packages...                                           
> [2/4] Fetching packages...                                            
> info There appears to be trouble with your network connection.
> Retrying...                                                           
> info There appears to be trouble with your network connection.
> Retrying...                                                           
> info There appears to be trouble with your network connection.
> Retrying...                                                           
> info There appears to be trouble with your network connection.
> Retrying...                                                           
> info There appears to be trouble with your network connection.
> Retrying...                                                           
> info There appears to be trouble with your network connection.
> Retrying...                                                           
> info There appears to be trouble with your network connection.
> Retrying...                                                           
> error An unexpected error occurred:
> "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.179.0.tgz:
> ESOCKETTIMEDOUT".

我尝试增加 yarn 的超时时间,但错误仍然发生

我甚至无法在容器上执行 bash(它会永远卡住)或任何其他命令(即:尝试重现纱线问题)

而且 _SupervisorLog 似乎没有映射,文件夹是空的,我无法准确理解发生了什么,也无法正确重现错误

如果我尝试访问该 URL,有时会收到错误网关,有时甚至不会收到错误网关。如果我尝试访问应该加载“前端”的路径,则会收到“禁止”错误。需要澄清的是,当我使用 docker-compose 在本地运行容器时,此操作运行正常。

我最近开始使用 Docker,因此请随意指出您在我的文件中发现的任何其他问题。

相关内容