DOCKER - 4 5 Push on Docker Hub
This lesson continues the previous one on image tags — now we push our tagged image to Docker Hub. Running docker image push myaccount/my-nginx straight away fails with access denied: Docker tried to push to your account, but you're not logged in. The CLI has docker login and docker logout commands; with a free Docker Hub account you can authenticate directly from the terminal.
Login, push, and add extra tags
docker login
docker image push myaccount/my-nginx
Once authenticated, the push succeeds. Refresh your Docker Hub profile and you'll see the new repository. Notice that we never created the repo manually — pushing a tagged image with a name like myaccount/my-nginx automatically creates a public repo, defaulting the tag to latest if none was supplied. You can later edit the repo description, set permissions, or add documentation through the Hub UI.
To add another tag to the same image and push it as well:
docker image tag myaccount/my-nginx myaccount/my-nginx:testing
docker image push myaccount/my-nginx:testing
The output shows "Layer already exists" for every layer except the new tag manifest — Docker doesn't re-upload the bytes, it just registers a new reference. Refresh Docker Hub and the new tag appears alongside latest.
docker login/docker logout— manage CLI credentials (session token stored locally)- Pushing a new tag like
myaccount/repoauto-creates the repo as public - For a private repo, create it on Docker Hub first with privacy set, then push — the bits won't go public mid-flight
- If you're on a shared machine, run
docker logoutso your session token isn't left behind
To recap: tags must follow the <user-or-org>/<repo>:<tag> format to be pushable, multiple tags can share one image ID, and the convention on Docker Hub is that latest points to the most recent stable release of your software.
Summary
This lesson teaches how to push Docker images to Docker Hub. The key requirement is authenticating first with `docker login`; without credentials, push operations fail with "access denied." Images must be tagged in the format `docker-id/image-name:tag` to work with Docker Hub, and multiple tags can reference the same image. The tutorial covers automatic repository creation for public images, the "latest" tag convention, private repository setup, and proper logout procedures.
Key points
- Use `docker login` to authenticate with Docker Hub before any push operation (credentials stored locally in config)
- Images must follow the naming format `docker-id/image-name:tag` to push successfully to Docker Hub
- Multiple tags can point to the same image ID; tagging an existing image doesn't duplicate the underlying layers
- The 'latest' tag is Docker's default convention but is just a label—you can add and manage additional custom tags
- Public repositories are auto-created on first push, but private repositories must be created manually in Docker Hub
- Use `docker logout` to clear stored credentials from local config (important on shared or Linux servers)
FAQ
Why did I get 'access denied' when pushing my image to Docker Hub?
You must authenticate first using `docker login` from the command line. Without valid Docker Hub credentials, push operations are rejected with access denied errors.
What happens when I push an image with a tag that doesn't exist on Docker Hub yet?
Docker Hub automatically creates a new repository based on the tag name. For public repositories, no manual setup is needed—the image becomes available immediately. For private repos, you must create the repository first.
Can I have multiple tags pointing to the same Docker image?
Yes. You can tag the same image multiple times with different tags using `docker tag`. Each tag is just a label pointing to the same underlying image ID, and pushing multiple tags reuses existing layers without duplication.