Skip to content

Commit 6fed46a

Browse files
author
Aaron Lehmann
committed
Pass authentication credentials through to build
In Docker 1.10 and earlier, "docker build" can do a build FROM a private repository that hasn't yet been pulled. This doesn't work on master. I bisected this to moby#19414. AuthConfigs is deserialized from the HTTP request, but not included in the builder options. Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
1 parent 2a16099 commit 6fed46a

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

api/server/router/build/build_routes.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ func (br *buildRouter) postBuild(ctx context.Context, w http.ResponseWriter, r *
159159
buildOptions.Dockerfile = dockerfileName
160160
}
161161

162+
buildOptions.AuthConfigs = authConfigs
163+
162164
out = output
163165
if buildOptions.SuppressOutput {
164166
out = notVerboseBuffer

integration-cli/docker_cli_build_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6534,3 +6534,26 @@ func (s *DockerSuite) TestBuildWorkdirWindowsPath(c *check.C) {
65346534
c.Fatal(err)
65356535
}
65366536
}
6537+
6538+
func (s *DockerRegistryAuthSuite) TestBuildFromAuthenticatedRegistry(c *check.C) {
6539+
dockerCmd(c, "login", "-u", s.reg.username, "-p", s.reg.password, "-e", s.reg.email, privateRegistryURL)
6540+
6541+
baseImage := privateRegistryURL + "/baseimage"
6542+
6543+
_, err := buildImage(baseImage, `
6544+
FROM busybox
6545+
ENV env1 val1
6546+
`, true)
6547+
6548+
c.Assert(err, checker.IsNil)
6549+
6550+
dockerCmd(c, "push", baseImage)
6551+
dockerCmd(c, "rmi", baseImage)
6552+
6553+
_, err = buildImage(baseImage, fmt.Sprintf(`
6554+
FROM %s
6555+
ENV env2 val2
6556+
`, baseImage), true)
6557+
6558+
c.Assert(err, checker.IsNil)
6559+
}

0 commit comments

Comments
 (0)