Search code examples
imageamazon-web-servicesdockerdocker-composedocker-swarm

Why can't pull images from ecr on aws automatically in a docker swarm cluster?


Use this way to deploy an application which has been built as a docker image hosted on ecr:

version: "3"
services:
  web:
    image: [AWS_ECR_REPO_URL]/app0:latest
    deploy:
      replicas: 5
      restart_policy:
        condition: on-failure
      resources:
        limits:
          cpus: "0.1"
          memory: 50M
    ports:
      - "80:80"
    networks:
      - webnet
networks:
  webnet:

Deploy it:

$ docker stack deploy -c docker-compose.yml app0

Then use docker images to check the images local, can't find the [AWS_ECR_REPO_URL]/app0:latest at all.

If pull the repo myself, it can be get:

$ docker pull [AWS_ECR_REPO_URL]/app0:latest

I don't know why.


Solution

    • Enter your credentials using docker login if you want to pull the private image.

    • Specify server name want to login into self-hosted registry

      docker login server-name (localhost)

    • Use --with-registry-auth option for swarm

      docker stack deploy --with-registry-auth