Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
559 views
in Technique[技术] by (71.8m points)

docker - Logged in to ACR on the host, can I use that inside container?

We're moving our Jenkins setup to Azure.

Once I have an Azure node, I run the following:

az login -i
az acr login -n myregistry

From there, I can pull images from the registry.

My container has the docker socket mapped inside and it interacts with docker on the host to bring up more containers. But when I try to docker pull from inside the container, I get

docker: Error response from daemon: Get https://myregistry.azurecr.io/v2/myimage/manifests/mytag:
 unauthorized: authentication required, visit https://aka.ms/acr/authorization for more information.
See 'docker run --help'.

One way to solve the issue is to have az installed in my container and invoke the same login on startup. I would like however not to modify the image.

Are there any other ways to use the fact that the host is already authorized for ACR? Is there any folder in the host that I can map inside my container so that it would use the host's login information?

Thanks

question from:https://stackoverflow.com/questions/65832330/logged-in-to-acr-on-the-host-can-i-use-that-inside-container

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

When you use the Azure CLI command az acr login, then it will store the credential to your docker credential file ~/.docker/config.json. So you can mount the docker credential file to the same path of the container. Then the docker inside the container can also use the credential to pull images from your ACR.

Update:

Why not work, docker stores the credential in the file /home/user/.docker/config.json. When you use Azure CLI command az acr login, it will use the current use that you use to login with the command az login and then stores the credential for your local docker server. Here is the example via the way I provide you:

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...