0

How can I add the docker hub credentials in docker-compose.yml and pull the private image?

I want to pull 2 images from 2 different private repositories?

J. Scott Elblein
  • 4,013
  • 15
  • 58
  • 94
ranjitha rao
  • 57
  • 3
  • 6

2 Answers2

1

To push to or pull from private registry, you just need to add the registry’s location to the repository name. It will look like my.registry.address:port/repositoryname

On a fresh build it looks as follows

docker push localhost.localdomain:5000/ubuntu
Username (): user
Password:
Email (): user@pass.com

Then you can use docker login multiple times before running docker-compose, one for each registry, and they will stack.

Marius Jaraminas
  • 813
  • 1
  • 7
  • 19
  • Thanks Marius. But I want to pull images from 2 different private repositories in the same docker-compose file.Is that possible? – ranjitha rao Jan 09 '20 at 15:24
0

You need to use docker login before invoking docker-compose:

https://docs.docker.com/engine/reference/commandline/login/

You would do something like this

services:
  s1:
    image: repo.foo.com/s1

  s2:
    image: repo.bar.com/s2

You would login once and Docker would remember your credentials:

docker login -u user1 -p pass1 https://repo.foo.com
docker login -u user2 -p pass2 https://repo.bar.com

and then you would run docker-compose as many times as you need.

Delta George
  • 2,560
  • 2
  • 17
  • 11
  • Thanks Oleg. But I want to pull images from 2 different private repositories in the same docker-compose file.Is that possible? – ranjitha rao Jan 09 '20 at 15:14