在 ElasticBeanstalk 上部署多容器应用程序时出现 CannotPullContainerError
Posted
技术标签:
【中文标题】在 ElasticBeanstalk 上部署多容器应用程序时出现 CannotPullContainerError【英文标题】:CannotPullContainerError on Deploying Multi-container App on ElasticBeanstalk 【发布时间】:2019-03-28 11:05:38 【问题描述】:我有一个多容器应用程序,我想在 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
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
当我在我的本地系统上运行它时,我的工作文件。但是当我将它上传到 elasticbeanstalk 上时,它给出了我的以下错误。
ECS 任务因以下原因停止:任务中的基本容器已退出。 (芹菜: db:cbeat:web:CannotPullContainerError:API 错误(404):拉取访问 docker_test 被拒绝,存储库不存在或可能需要 'docker login' redis:)
我使用container-transform 将docker-compose.yml
转换为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": []
我该如何解决这个问题?
【问题讨论】:
【参考方案1】:请将镜像“docker_test”推送到 dockerhub 或 ECR 以便 Beanstalk 从中提取镜像。目前,它在您的本地并且 ECS 代理不知道它。
-
标记并推送
docker_test
映像到 dockerhub 和 ECR 等注册表。
更新Dockerrun.aws.json
中的图片回购网址。
允许 Beanstalk 拉取图像。
【讨论】:
我如何允许 Beanstalk 拉取图像?【参考方案2】:我对 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
【讨论】:
以上是关于在 ElasticBeanstalk 上部署多容器应用程序时出现 CannotPullContainerError的主要内容,如果未能解决你的问题,请参考以下文章
如何配置github操作将docker容器部署到aws elasticbeanstalk多容器环境
在 Elasticbeanstalk for Scala Apps 中为 Docker 多容器环境部署和托管工件的最佳实践是啥?
Elastic Beanstalk 多容器 Docker 环境变量
Elastic Beanstalk 上的多容器 Docker 环境中的容器连接被拒绝