繁体   English   中英

在ElasticBeanstalk上部署多容器应用程序时出现CannotPullContainerError

[英]CannotPullContainerError on Deploying Multi-container App on ElasticBeanstalk

我有一个要在ElasticBeanstalk上部署的多容器应用程序。 以下是我的文件。

Dockerfile

FROM python:2.7

WORKDIR /app

ADD . /app

RUN apt-get update && \
    apt-get upgrade -y && \
    apt-get install -y \
    apt-utils \
    git \
    python \
    python-dev \
    libpcre3 \
    libpcre3-dev \
    python-setuptools \
    python-pip \
    nginx \
    supervisor \
    default-libmysqlclient-dev \
    python-psycopg2 \
    libpq-dev \
    sqlite3 && \
    pip install -U pip setuptools && \
    rm -rf /var/lib/apt/lists/*

RUN pip install -r requirements.txt

EXPOSE 8000

RUN chmod +x entry_point.sh

泊坞窗,compose.yml

version: "2"
services:
  db:
    restart: always
    container_name: docker_test-db
    image: postgres:9.6
    expose:
      - "5432"
    mem_limit: 10m
    environment:
      - POSTGRES_NAME=postgres
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=docker_test

  redis:
    restart: always
    image: redis:3.0
    expose:
      - "6379"
    mem_limit: 10m

  web:
    # replace username/repo:tag with your name and image details
    restart: always
    build: .
    image: docker_test
    container_name: docker_test-container
    ports:
      - "8000:8000"
    environment:
      - DATABASE=db
      - POSTGRES_NAME=postgres
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=docker_test
    mem_limit: 500m
    depends_on:
      - db
      - redis
    entrypoint: ./entry_point.sh
    command: gunicorn docker_test.wsgi:application -w 2 -b :8000 --timeout 120 --graceful-timeout 120 --worker-class gevent

  celery:
    image: docker_test
    container_name: docker_test-celery
    command: celery -A docker_test worker -l info
    links:
      - db
      - redis
    mem_limit: 10m
    depends_on:
      - web

  cbeat:
    image: docker_test
    container_name: docker_test-cbeat
    command: celery beat --loglevel=info
    links:
      - db
      - redis
    mem_limit: 10m
    depends_on:
      - web

在本地系统上运行文件时,我会工作。 但是,当我将其上传到elasticbeanstalk时,出现了以下错误。

由于以下原因,ECS任务已停止:退出了任务中的基本容器。 (celery:db:cbeat:web:CannotPullContainerError:API错误(404):拒绝docker_test的访问权限,存储库不存在或可能需要'docker login'redis:)

我通过使用container-transformDockerrun.aws.json docker-compose.yml转换为Dockerrun.aws.json 对于上面的文件, Dockerrun.aws.json是我的Dockerrun.aws.json

{
    "AWSEBDockerrunVersion": 2,
    "containerDefinitions": [
        {
            "command": [
                "celery",
                "beat",
                "--loglevel=info"
            ],
            "essential": true,
            "image": "docker_test",
            "links": [
                "db",
                "redis"
            ],
            "memory": 10,
            "name": "cbeat"
        },
        {
            "command": [
                "celery",
                "-A",
                "docker_test",
                "worker",
                "-l",
                "info"
            ],
            "essential": true,
            "image": "docker_test",
            "links": [
                "db",
                "redis"
            ],
            "memory": 10,
            "name": "celery"
        },
        {
            "environment": [
                {
                    "name": "POSTGRES_NAME",
                    "value": "postgres"
                },
                {
                    "name": "POSTGRES_USER",
                    "value": "postgres"
                },
                {
                    "name": "POSTGRES_PASSWORD",
                    "value": "postgres"
                },
                {
                    "name": "POSTGRES_DB",
                    "value": "docker_test"
                }
            ],
            "essential": true,
            "image": "postgres:9.6",
            "memory": 10,
            "name": "db"
        },
        {
            "essential": true,
            "image": "redis:3.0",
            "memory": 10,
            "name": "redis"
        },
        {
            "command": [
                "gunicorn",
                "docker_test.wsgi:application",
                "-w",
                "2",
                "-b",
                ":8000",
                "--timeout",
                "120",
                "--graceful-timeout",
                "120",
                "--worker-class",
                "gevent"
            ],
            "entryPoint": [
                "./entry_point.sh"
            ],
            "environment": [
                {
                    "name": "DATABASE",
                    "value": "db"
                },
                {
                    "name": "POSTGRES_NAME",
                    "value": "postgres"
                },
                {
                    "name": "POSTGRES_USER",
                    "value": "postgres"
                },
                {
                    "name": "POSTGRES_PASSWORD",
                    "value": "postgres"
                },
                {
                    "name": "POSTGRES_DB",
                    "value": "docker_test"
                }
            ],
            "essential": true,
            "image": "docker_test",
            "memory": 500,
            "name": "web",
            "portMappings": [
                {
                    "containerPort": 8000,
                    "hostPort": 8000
                }
            ]
        }
    ],
    "family": "",
    "volumes": []
}

我该如何解决这个问题?

请将映像“ docker_test”推送到dockerhub或ECR,以便Beanstalk从中提取映像。 目前,它在您的本地上,而ECS代理对此一无所知。

  1. docker_test映像标记并推docker_test dockerhub和ECR等注册表。
  2. 更新Dockerrun.aws.json图像Dockerrun.aws.json URL。
  3. 允许Beanstalk提取图像。

我对EB不太熟悉,但是对ECR和ECS却很熟悉。

当我尝试从ECR上的空存储库中提取映像时,通常会收到该错误,换句话说,已创建了ECR存储库,但您尚未将任何Docker映像推送到存储库。

当您尝试从ECR提取图像并且在标签中找不到图像的版本号时,也会发生这种情况。 我建议您将docker-compose.yml文件更改为使用最新版本的图像。 这意味着到处提及镜像docker_test的地方都需要在其后缀“:latest”,如下所示:

image: docker_test:latest

我将在回复末尾发布我为您制作的整个docker-compose.yml。

我建议您看一下此文档: https : //docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_docker.container.console.html请参阅部分:“使用Amazon ECR存储库中的图像”他们解释了如何解决docker登录问题。

希望对您有所帮助。 如果对此有任何疑问,请回复。

version: "2"
services:
  db:
    restart: always
    container_name: docker_test-db
    image: postgres:9.6
    expose:
      - "5432"
    mem_limit: 10m
    environment:
      - POSTGRES_NAME=postgres
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=docker_test

  redis:
    restart: always
    image: redis:3.0
    expose:
      - "6379"
    mem_limit: 10m

  web:
    # replace username/repo:tag with your name and image details
    restart: always
    build: .
    image: docker_test:latest
    container_name: docker_test-container
    ports:
      - "8000:8000"
    environment:
      - DATABASE=db
      - POSTGRES_NAME=postgres
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=docker_test
    mem_limit: 500m
    depends_on:
      - db
      - redis
    entrypoint: ./entry_point.sh
    command: gunicorn docker_test.wsgi:application -w 2 -b :8000 --timeout 120 --graceful-timeout 120 --worker-class gevent

  celery:
    image: docker_test
    container_name: docker_test-celery
    command: celery -A docker_test worker -l info
    links:
      - db
      - redis
    mem_limit: 10m
    depends_on:
      - web

  cbeat:
    image: docker_test:latest
    container_name: docker_test-cbeat
    command: celery beat --loglevel=info
    links:
      - db
      - redis
    mem_limit: 10m
    depends_on:
      - web

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM