Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker build can't pull base image with this ecr-login helper? #9

Closed
gengmao opened this issue Aug 17, 2016 · 8 comments
Closed

docker build can't pull base image with this ecr-login helper? #9

gengmao opened this issue Aug 17, 2016 · 8 comments

Comments

@gengmao
Copy link

gengmao commented Aug 17, 2016

Hello,

I rolled out this ecr-login helper a few days ago, and I found docker build failed with unauthorized: authentication required if the Dockerfile is FROM an image in ECR.

This ecr-login helper works fine with docker pull. The error can be worked around by pulling the image before docker build, but if the docker build has an --pull option, the build would failed with same unauthorized: authentication required error.

I don't know the details of how docker build pulls an private image when needed - is this an simple implementation issue, or just any https://github.com/docker/docker-credential-helpers can't work with docker build?

@samuelkarp
Copy link
Contributor

@gengmao Thanks for reporting this. I did a little investigation and it looks like the Docker CLI uses the auths section in ~/docker/config.json to find which registries it needs credentials for instead of parsing the FROM line in the Dockerfile. I was able to get docker build to work by changing my ~/docker/config.json file to this:

{
    "credsStore":"ecr-login",
    "auths": {
        "123456789012.dkr.ecr.us-west-2.amazonaws.com": {
        }
    }
}

As a workaround, you can adjust your ~/.docker/config.json file to include empty sections for each ECR endpoint (account + region) you intend to use. For a better fix, I think it would be a good idea for docker build to parse the FROM line and only send the set of credentials necessary to build that Dockerfile to the Docker daemon.

@gengmao
Copy link
Author

gengmao commented Aug 20, 2016

Adding "auths" solved my problem. Thanks @samuelkarp!
I am closing this issue. Just probably worth to mention the docker build behavior in readme.md, for people like me who do not recall it.

@burdandrei
Copy link

I know this is closed, but adding the auth section stopped to help after the upgrade from 1.12 up.
We received new trusty images in travis-ci, and all our builds failed.
It works now only if we're running docker pull before build.

@samuelkarp
Copy link
Contributor

@burdandrei In more-recent versions of Docker, the auths section is no longer use for determining which credentials to send to the daemon. The long-term solution here is going to be a smarter Docker CLI that parses the FROM line and explicitly requests the appropriate credentials from the credential helper (work has started in moby/moby#32967, but it doesn't look like there's current movement). In the short-term, you can either do a docker pull like you're doing or let the credential helper pre-cache credentials like this echo $registry | docker-credential-ecr-login get.

shumkov added a commit to dashevo/js-drive that referenced this issue Apr 16, 2018
shumkov added a commit to dashevo/js-drive that referenced this issue Apr 16, 2018
shumkov added a commit to dashevo/js-drive that referenced this issue Apr 17, 2018
* add credentials helper

* remove aws get-login

* fix travis.yml

* fix travis.yml

* fix travis

* specify deploy branch

* exit immediately if error

* fix pulling on build awslabs/amazon-ecr-credential-helper#9

* fix docker config

* fix awslabs/amazon-ecr-credential-helper#9

* move credentials to before_install section

* change deploy branch to master
@miked0004
Copy link

This is not limited to docker compose and the solution of piping to the credential plugin seems less useful than the basic aws ecr get-login --no-include-email.
Is there any solution in the works here?

@joshenders
Copy link

Encountered this issue today. Ended up using the echo $registry | docker-credential-ecr-login get approach which resolved the issue for me. I echo the sentiments of others, wishing the docker cli would parse the FROM directive in my Dockerfile.

@samuelkarp
Copy link
Contributor

I echo the sentiments of others, wishing the docker cli would parse the FROM directive in my Dockerfile.

Me too! Unfortunately, this change needs to be made in the Docker CLI itself rather than in this project. moby/moby#32967 looks stalled, but that's where the work would need to happen.

@rdpa
Copy link

rdpa commented Dec 3, 2019

For anyone still experiencing this issue, using the docker daemon with buildkit solves the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants