I have a docker image tagged as me/my-image
, and I have a private repo on the dockerhub named me-private
.
When I push my me/my-image
There are two options:
Go into the hub, and create the repository first, and mark it as private. Then when you push to that repo, it will be private. This is the most common approach.
log into your docker hub account, and go to your global settings. There is a setting that allows you to set what your default visability is for the repositories that you push. By default it is set to public, but if you change it to private, all of your repositories that you push will be marked as private by default. It is important to note that you will need to have enough private repos available on your account, or else the repo will be locked until you upgrade your plan.
You need to tag your image correctly first with your registryhost
:
docker tag [OPTIONS] IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]
Then docker push using that same tag.
docker push NAME[:TAG]
Example:
docker tag 518a41981a6a myRegistry.com/myImage
docker push myRegistry.com/myImage
Create repository on dockerhub :
$docker tag IMAGE_ID UsernameOnDockerhub/repoNameOnDockerhub:latest
$docker push UsernameOnDockerhub/repoNameOnDockerhub:latest
Note : here "repoNameOnDockerhub" : repository with the name you are mentioning has to be present on dockerhub
"latest" : is just tag
Simple working solution:
Go here https://hub.docker.com/
to create a PRIVATE repository with name for example johnsmith/private-repository
this is the NAME/REPOSITORY
you will use for your image when building the image.
First, docker login
Second, I use "docker build -t johnsmith/private-repository:01 .
" (where 01 is my version name) to create image, and I use "docker images
" to confirm the image created such as in this yellow box below: (sorry I can not paste the table format but the text string only)
johnsmith/private-repository(REPOSITORY) 01(TAG) c5f4a2861d6e(IMAGE ID) 2 days ago(CREATED) 305MB(SIZE)
docker push johnsmith/private-repository:01
(Your private repo will be here example https://hub.docker.com/r/johnsmith/private-repository/)Done!
Just three simple steps:
docker login --username username
--password
which is recommended as it doesn't store it in your command historydocker tag my-image username/my-repo
docker push username/my-repo
Ref: dock.docker.com
This topic provides basic information about deploying and configuring a registry
Before you can deploy a registry, you need to install Docker on the host.
Use a command like the following to start the registry container:
start_registry.sh
#!/bin/bash
docker run -d \
-p 5000:5000 \
--restart=always \
--name registry \
-v /data/registry:/var/lib/registry \
registry:2
Pull the ubuntu:16.04
image from Docker Hub.
$ docker pull ubuntu:16.04
Tag the image as localhost:5000/my-ubuntu
. This creates an additional tag for the existing image. When the first part of the tag is a hostname and port, Docker interprets this as the location of a registry, when pushing.
$ docker tag ubuntu:16.04 localhost:5000/my-ubuntu
Push the image to the local registry running at localhost:5000
:
$ docker push localhost:5000/my-ubuntu
Remove the locally-cached images. This does not remove the localhost:5000/my-ubuntu
image from your registry.
$ docker image remove ubuntu:16.04
$ docker image remove localhost:5000/my-ubuntu
Pull the localhost:5000/my-ubuntu
image from your local registry.
$ docker pull localhost:5000/my-ubuntu
According to docs.docker.com, this is very insecure and is not recommended.
Edit the daemon.json
file, whose default location is /etc/docker/daemon.json
on Linux or C:\ProgramData\docker\config\daemon.json
on Windows Server. If you use Docker for Mac
or Docker for Windows
, click Docker icon -> Preferences -> Daemon
, add in the insecure registry
.
If the daemon.json
file does not exist, create it. Assuming there are no other settings in the file, it should have the following contents:
{
"insecure-registries" : ["myregistrydomain.com:5000"]
}
With insecure registries enabled, Docker goes through the following steps:
Restart Docker for the changes to take effect.