Muhammad Hassan
Muhammad Hassan

Reputation: 14391

CannotPullContainerError on Deploying Multi-container App on ElasticBeanstalk

I have a multi-container app which I want to deploy on ElasticBeanstalk. Below are my files.

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

docker-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

I works file when I run it on my local system. But when I upload it on elasticbeanstalk, It gives my following error.

ECS task stopped due to: Essential container in task exited. (celery: db: cbeat: web: CannotPullContainerError: API error (404): pull access denied for docker_test, repository does not exist or may require 'docker login' redis: )

I transform docker-compose.yml to Dockerrun.aws.json by using container-transform. For above file, my Dockerrun.aws.json is following.

{
    "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": []
}

How can I resolve this problem?

Upvotes: 0

Views: 565

Answers (2)

OpenBSDNinja
OpenBSDNinja

Reputation: 1069

I'm not that familiar with EB, but I am pretty familiar with ECR and ECS.

I usually get that error when I try pull an image from an empty repo on ECR, in other words the ECR repo was created but you havn't pushed any docker images to the repo yet.

This can also happen when you try pull an image from ECR and it can't find the version number of the image in the tag. I suggest that you change your docker-compose.yml file to use the latest version of the images. This will mean that everywhere you mention the image docker_test you will need suffix it with ":latest" Something like this:

image: docker_test:latest

I will post my whole docker-compose.yml I made for you at the end of the reply.

I would suggest that you have a look at this doc:https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_docker.container.console.html see the section:"Using Images from an Amazon ECR Repository" they explain how you can resolve the docker login issue.

I hope that helps. Please reply if you have any questions regarding this.

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

Upvotes: 1

vivekyad4v
vivekyad4v

Reputation: 14903

Please push the image "docker_test" to either dockerhub or ECR for Beanstalk to pull image from. Currently, it's on your local & the ECS agent doesn't know about it.

  1. Tag & Push docker_test image to a registry like dockerhub & ECR.
  2. Update image repo URL in Dockerrun.aws.json.
  3. Allow Beanstalk to pull the image.

Upvotes: 2

Related Questions