
Docker buildDocker authentication error
I’ve recently started to learn about Docker.
It’s a tool any developer, or devOps engineer (what’s the difference) should know about, including some practical experience :O)
I started following a Spring Boot guide, which was running a spring boot application in a docker container.
Everything was going just fine, until I came to the step:
$ gradle build buildDocker
I got the following error message (output):
[snip]
Removing intermediate container e20f0c98278d
Step 6 : ENTRYPOINT sh -c java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar
---> Running in 443f888aa5b9
---> 876baec689fd
Removing intermediate container 443f888aa5b9
Successfully built 876baec689fd
:buildDocker FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':buildDocker'.
> Docker execution failed
Command line [docker push chocksaway/gs-spring-boot-docker:latest] returned:
unauthorized: authentication required
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
The Solution
If you look in build.gradle, you will see that push = true:
// tag::task[]
task buildDocker(type: Docker, dependsOn: build) {
push = true
applicationName = jar.baseName
dockerfile = file('src/main/docker/Dockerfile')
doFirst {
copy {
from jar
into stageDir
}
}
}
After some rummaging round, I found that I needed to authenticate myself with docker hub.
You could set push = false, but you should set up your docker hub.
If you push to a docker hub, you will need to:
- Register with docker hub docker hub.
- Authenticate yourself with docker hub, by running:
$ docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: my_user_id
Password: ********
Login Succeeded
rhubarb:complete milesd$
The next time you do a “gradle build buildDocker”, you will see that the push, and BUILD are successful:
f3734205bcbc: Pushed
latest: digest: sha256:5ef9119044f5760a20f50def372f312fd9dab0f8a7dd6fc9f6c978e547686c3e size: 1375
BUILD SUCCESSFUL
When you login into docker hub, you will see that the repository is listed.