I'm slow to add yet another answer, but the accepted answer and remaining answers mentioning docker login
are missing an edge case to solve the issues others are stating in comments.
docker login <private-repo-host>:<port>
Emphasis on the port
needing to be entered is likely the solution for those still searching. docker login
or docker login <private-repo-host>
may connect without issue, but when it comes time to push images, you'll get the same error as OP.
That is, you can connect w/o defining host or port and still get the:
...
Login Succeeded
In my case, I am using a self hosted GitLab's built in docker-registry, which was setup to use port 4567
. It may be adventagous to verify what port the registry must be accessed from. Without specifying said port docker login <our.gitlab.host>
would login successful, but give the same issue the OP inquired about:
...
The push refers to repository [...]
denied: access forbidden
If you're using docker.io/dockerhub you're likely not going to have this problem, but if you have a self hosted/private registry solution the probability increases you need to explicitly login using both the host and port for the docker registry.