Sub topic 11
Fixing common push errors
This chapter assumes you can already build an image, log in with docker login, and run docker tag and docker push as shown in the earlier chapters. You also need to know that an image name has a namespace, a repository, and a tag. Here you will learn to read a failed push, find which part of the chain broke, and fix it.
How a push fails
A push depends on four things, and an error nearly always points at one of them:
- The local image exists under the exact name you typed.
- The name points at a repository you are allowed to write to.
- The CLI holds credentials that Docker Hub accepts.
- Those credentials have write permission for that repository.
The CLI also needs a working network path to the registry, but that failure looks different from the other four.
Read the whole message first
Docker prints the failing step, then the registry's reply. The registry's reply is the useful part. It is usually a short code such as denied, unauthorized, or toomanyrequests, followed by text. Copy the full line into your notes before changing anything. Several different causes produce similar text, and you need the exact wording to tell them apart.
| Message fragment | Likely cause | Fix |
|---|---|---|
| `An image does not exist locally with the tag` | The name you pushed was never created | Run `docker images`, then `docker tag` |
| `denied: requested access to the resource is denied` | Wrong namespace, not logged in, or no write permission | Check name, login, and token scope |
| `push access denied, repository does not exist or may require authorization` | Same family: the client could not write to that name | Same checks as above |
| `unauthorized: incorrect username or password` | Bad credentials, or a password used where a token is required | Log in again with a valid token |
| `unauthorized: authentication required` | No credentials sent for this registry | Run `docker login` |
| `invalid reference format: repository name must be lowercase` | Uppercase letters in the repository name | Rename in lowercase |
| `TLS handshake timeout`, `connection reset`, `500` | Network or registry trouble | Retry, then check proxy and DNS |
Image does not exist locally
An image does not exist locally with the tag: YOUR_USERNAME/myappTwo things cause this. You may have forgotten docker tag, or you left off the tag part. When you omit the tag, Docker pushes latest. If you only ever built myapp:1.0, then YOUR_USERNAME/myapp:latest does not exist.
List what you have:
docker images --format '{{.Repository}}:{{.Tag}}'Then create the missing name, using the exact tag you intend to publish:
docker tag myapp:1.0 YOUR_USERNAME/myapp:1.0
docker push YOUR_USERNAME/myapp:1.0Pushing a bare repository name with no tag in the command also makes the older Docker releases push every local tag of that repository. Newer releases push only latest. Always type the tag.
Denied: requested access to the resource is denied
This is the most common failure, and it has four distinct causes. Check them in this order, because the first is the most frequent.
The name has no namespace
If you run docker push myapp:1.0, Docker reads the name as docker.io/library/myapp:1.0. The library namespace belongs to Docker's official images, and you cannot write to it. The registry replies with denied. The fix is to tag the image with your own namespace first:
docker tag myapp:1.0 YOUR_USERNAME/myapp:1.0
docker push YOUR_USERNAME/myapp:1.0Spelling matters here as well. A typo in the namespace points at a namespace that either does not exist or belongs to someone else, and the reply is again denied. Docker Hub does not distinguish between "does not exist" and "exists but not yours" in this message. That is deliberate, because it stops people from probing for account names.
You are not logged in, or logged in as someone else
A fresh shell, a new machine, or a logout can leave the CLI with no credentials. You can also be logged in as a different account than the namespace you are pushing to, for example a personal account while pushing to a work namespace.
Look at what the CLI has stored:
cat ~/.docker/config.jsonLook for an auths entry for https://index.docker.io/v1/. If the file has a credsStore or credHelpers setting, the secret and often the username live in your operating system's credential store instead, and the entry in auths is empty. In that case the file only shows that something is stored. To start from a known state, log out and log in again:
docker logout
docker login -u YOUR_USERNAMEThe token is read-only
docker login succeeds with any valid credential, including a personal access token whose scope is only Read. The failure appears later, at push time, as denied. Login success tells you the token is genuine, not that it can write.
Open your Docker Hub account settings, find the token under personal access tokens, and check its access permission. Pushing needs Read & Write or higher. You cannot edit the scope of an existing token, so create a new token with the right scope and log in with it.
You lack permission in an organization namespace
When the namespace is an organization, such as acme/myapp, your personal account needs membership in a team that has write access. A person with read access can pull but not push, and the registry answers denied. Ask an organization owner to adjust your team's permission on that repository or to give you a role that can write.
Unauthorized messages
unauthorized: incorrect username or password means the registry rejected the credential itself. Check these in order:
- The username is your Docker ID, not your email address, when you log in with the CLI.
- The token was copied completely, without a trailing space or newline.
- The token has not been deleted or deactivated in your account settings.
- If you use two-factor authentication, you are supplying a personal access token and not your account password. A password does not work from the CLI in that situation.
When you script the login, a stray character in the secret is the usual culprit. Use the stdin form so the secret is read exactly as stored:
echo "$DOCKERHUB_TOKEN" | docker login -u YOUR_USERNAME --password-stdinConfirm the variable is set before you blame Docker. An empty variable produces a login attempt with an empty secret and a confusing message.
test -n "$DOCKERHUB_TOKEN" && echo "token is set" || echo "token is empty"unauthorized: authentication required is different. It means the request carried no credentials at all. Run docker login, and if you already did, check that you are using the same user account and Docker context. A sudo docker push runs as root and reads root's ~/.docker/config.json, not yours, so credentials stored under your own user are invisible to it.
Invalid reference format
invalid reference format: repository name must be lowercaseRepository names may contain only lowercase letters, digits, and the separators ., _, and -. A name such as YOUR_USERNAME/MyApp is rejected on the client before any network call. Note that the namespace is also lowercase on Docker Hub, so copying a display name with capitals into the command fails the same way. Lowercase everything:
docker tag myapp:1.0 your_username/myapp:1.0Tags are case-sensitive and may contain uppercase letters, but they cannot start with a period or dash and are limited to 128 characters.
Network and registry errors
Messages such as net/http: TLS handshake timeout, connection reset by peer, EOF, or received unexpected HTTP status: 500 do not point at your name or credentials. They come from the connection, a corporate proxy, or a temporary registry fault. A push is made of many layer uploads, and Docker retries each a few times before giving up.
- Re-run the same
docker push. Layers already uploaded are skipped, so a retry resumes close to where it stopped. - Test basic reachability with
curl -sI https://registry-1.docker.io/v2/. An HTTP 401 reply is healthy here: it means the registry answered and wants credentials. - If you sit behind a proxy, the Docker daemon needs the proxy settings, not only your shell. Setting
HTTPS_PROXYin your terminal does not change the daemon. - Check Docker's public status page if several users see the same failure at once.
A toomanyrequests reply is a rate limit. It appears mainly on pulls from anonymous or free accounts, but it can appear in CI where many jobs share one address. Logging in raises your allowance. It is not a problem with your image.
A repeatable checklist
When a push fails, work through these steps in order. Each one rules out a whole class of cause.
- Read the full error and note the registry's reply code.
- Run
docker imagesand confirm the exactnamespace/repository:tagexists locally. - Confirm the namespace is yours, or that your team can write to it, and that the name is lowercase.
- Run
docker logoutanddocker login, using a token with Read & Write scope. - Retry the push. If the failure changes, you have made progress, so read the new message from the top.
- If the message names a timeout or status 5xx, check the network, proxy, and status page.
Exercise
You run docker push myapp:1.0 after a successful docker login and get denied: requested access to the resource is denied. What is the most likely cause, and what are the two commands that fix it?
Show answer
The name has no namespace, so Docker targets docker.io/library/myapp, which you cannot write to. Run docker tag myapp:1.0 YOUR_USERNAME/myapp:1.0, then docker push YOUR_USERNAME/myapp:1.0.
Exercise
A CI job logs in with a personal access token and prints Login Succeeded, but the later push fails with denied. The image name is YOUR_USERNAME/myapp:latest and the namespace is correct. What do you check next, and why can login succeed?
Show answer
Check the token's access permission in Docker Hub account settings. A Read-only token authenticates successfully but cannot write. Because scope cannot be edited, create a new token with Read & Write access, update the secret, and rerun the job.