Sub topic 9
Choosing public or private visibility
This chapter assumes you can build an image, log in with docker login, and push a tagged image to your own Docker Hub repository. Here you decide who can see and pull what you push.
What visibility controls
Every Docker Hub repository is either public or private. Visibility applies to the whole repository, not to individual tags. If YOUR_USERNAME/myapp is public, then 1.0, latest, and every other tag in it are public.
- A public repository can be found in Docker Hub search and pulled by anyone, with or without an account.
- A private repository is visible only to you and to people you grant access to. Pulling from it requires
docker loginfirst.
Pushing always requires authentication in both cases. Visibility only affects who can read.
Comparing the two
| Aspect | Public | Private |
|---|---|---|
| Who can pull | Anyone, without logging in | Only you and collaborators who are logged in |
| Appears in search | Yes | No |
| Typical use | Open-source projects, base images, tutorials | Internal services, unreleased products, images with proprietary code |
| Free account limit | Unlimited | A limited number of repositories, which depends on your plan |
Check Docker's current pricing page for the exact private repository limit on your plan. The limit has changed over time.
Setting visibility
You choose visibility when you create the repository on Docker Hub. If you push to a repository that does not exist yet, Docker Hub creates it automatically. The default depends on your account settings, so check the result in the web interface after your first push instead of assuming.
To change it later:
- Sign in to Docker Hub and open the repository.
- Open the Settings tab.
- Under Visibility settings, choose to make the repository public or private, and confirm.
Pulling from a private repository
An anonymous pull from a private repository fails. Docker Hub does not confirm that the repository exists, so the error looks like a missing image.
docker logout
docker pull YOUR_USERNAME/private-app:1.0The pull fails with an error similar to pull access denied ... repository does not exist or may require 'docker login'. After you log in with an account that has access, the same command works:
docker login -u YOUR_USERNAME
docker pull YOUR_USERNAME/private-app:1.0Servers and CI runners that pull private images need credentials too. Use a personal access token with read-only permission for these, so a leaked token cannot be used to push.
Sharing a private repository
You have two main options for giving others access:
- Add individual collaborators to the repository. This is available for personal repositories on plans that support it.
- Create an organization, put the repository under the organization's namespace, and grant access through teams. Teams can have read, write, or admin permissions.
Prefer an organization when more than one person or system needs access. It keeps ownership out of one person's account.
A decision flow
Common mistakes
- Assuming a private repository hides secrets from your own team. Anyone with pull access can inspect every layer. Keep secrets out of images altogether and inject them at runtime.
- Forgetting to log in on the pulling machine. The error says the repository "does not exist", which sends people looking for a typo that is not there.
- Making a repository public to fix a pull error. Fix the credentials instead. Switching visibility to work around an authentication problem can expose images you meant to keep internal.
- Treating deletion as a cleanup. Once an image has been public, others may already have pulled it.
Exercise
A teammate reports that docker pull acme/billing-api:2.1 fails with "repository does not exist or may require 'docker login'". You know the name is spelled correctly and the repository is private. What are two likely causes, and what should you not do to fix it?
Show answer
Likely causes: the teammate is not logged in, or they are logged in with an account that has not been granted access to the repository. Fix it by having them run docker login with the right account and, if needed, adding them to the repository or to an organization team with read permission. Do not make the repository public just to make the pull work, because that exposes every tag and layer to everyone.