40

I'm using docker-compose command to run multiple containers. The problem is my docker-compose has to pull some images from the public repository and some from a private repository. What I'm planning to do is push all required images to the private repository but how can I make docker-compose pull the images from the private repository.

In short -> How to point to a private repository when the images are only available there

M.Babcock
  • 18,753
  • 6
  • 54
  • 84
utkarsh31
  • 1,439
  • 2
  • 13
  • 20
  • What registry are you using? – Serey Aug 08 '17 at 11:34
  • we are using jfrog – utkarsh31 Aug 08 '17 at 11:34
  • Accessing a private image should be the same as a public one, except for the authentication part. For example, your Dockerfile base image should still be something like this: `FROM private/repo:tag`, and should be the same in Docker Compose. Docker Hub and Amazon ECR can be accessed by using their CLI to authenticate, in your case, I can only point you to JFrog's registry page: [click here](https://www.jfrog.com/confluence/display/RTF/Docker+Registry) – Serey Aug 08 '17 at 11:38
  • 1
    We have an assumption that the end-user does not have the docker file. He only has a docker compose file which should automatically pull images he has mentioned in the `docker-compose.yml` file when when he does `docker-compose up` – utkarsh31 Aug 08 '17 at 11:42
  • 1
    Yes, so it should work the same way. I believe that JFrog gives you a custom URI for your private repository, but in order to gain access to that repository URI, you must authenticate or log-in. – Serey Aug 08 '17 at 11:47
  • Thanks @serey...login worked – utkarsh31 Aug 08 '17 at 12:09

1 Answers1

41

Use docker login command. (Official doc)
Enter your credentials, and then you can pull private image, only if you have an access.

If you want to login to a self-hosted registry you can specify this by adding the server name.

docker login localhost:8080

Thanks to @herm's comment, if you want to use swarm, use : --with-registry-auth option. Personnaly, I use this command :

docker stack deploy --with-registry-auth --compose-file dev.compose.yml myProjectName
callmemath
  • 8,185
  • 4
  • 37
  • 50
  • 7
    Fyi: when using docker stack deploy in a swarm the --with-registry-auth option will forward the login information to other nodes. – herm Aug 08 '17 at 12:20
  • 2
    If you host the image on a private Artifactory Enterprise server instance, you can't just do `docker login` `docker pull imageName`. You have to do `docker login artifactory.myCompany.com` `docker pull artifactory.myCompany.com/imageName:label`. However, even after logging in on the command line, and then running my docker-compose file which contains `image: artifactory.myCompany.com/imageName:label`, I still get the error `pull access denied for imageName, repository does not exist or may require 'docker login'` – cowlinator Apr 26 '20 at 01:57
  • I seemed to need to add an extra pull command e.g. `docker login && docker compose pull && docker compose up` or I'd get `failed to solve: rpc error: code = Unknown desc = failed to solve with frontend dockerfile.v0: failed to create LLB definition: failed to authorize: failed to fetch anonymous token: unexpected status: 401 Unauthorized` – djsutho Jun 02 '21 at 02:39