Reputation: 15544
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
, I end up always hitting the public repo.
What is the exact syntax to specifically push my image to my private repo?
Upvotes: 721
Views: 979803
Reputation: 8729
When pushing to a Docker Hub account, whether public or private, the process is the same.
The OP said:
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, I end up always hitting the public repo.
The immediate problem is that the private repo (me-private
) appears to have a different name than the image (my-image
). The repo and the image must have the same name (minus any tag).
TLDR;
An image named my-image
or my-image:tag
must have a repo name of my-image
.
Since the OP's repo was named me-private
,
Docker Hub wouldn't see those as the same and would create the new repo named my-image
.
(That new repo would be public by default, unless you change settings to make all your repositories private.)
As of June 2022, the process for setting up a Docker Hub repo is:
Given the following values:
username = yourusername
image name = theimage
tag = thetag
1) tag (or commit) the local image, adding a prefix with your username:
docker tag theimage:thetag yourusername/theimage:thetag
Notes:
docker tag theimage:thetag yourusername/yourorganizationname/theimage:thetag
latest
, :thetag
part can be left out; Docker assumes :latest
if you don't enter a :thetag
part2) push the prefixed image to Docker Hub:
docker push yourusername/theimage:thetag
OR
docker push yourusername/yourorganizationname/theimage:thetag
For a private repo, one of these extra steps is necessary:
Either
before step 1 above, create a private repository in your Docker Hub account
Remember that the repository name must be the same as theimage
that you're planning to push. Do not include a thetag
portion on the repository name. Eg, if your image is ubuntu:14.04
, you would name your repository ubuntu
. (All tagged images - eg, ubuntu:latest
, ubuntu:14.04
, etc - will go into the ubuntu
repo.)
Or
if you didn't create the repository in advance (which is not required!): go to your account in Docker Hub; click on the newly pushed repo, then its Settings tab - and make your repo private.
Upvotes: 15
Reputation: 451
After pull an image in local, you can do the next:
docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
Then docker push using that same tag.
docker push NAME[:TAG]
Example:
docker tag gvenzl/oracle-xe:21-slim quay.io/repository/yourDirectory/oracle_xe:oracle-xe
docker push quay.io/repository/yourDirectory/oracle_xe:oracle-xe
Upvotes: 2
Reputation: 337
If somebody looking for a quick way to push all images to a private repository, you can use my bash script - it will push all the Docker images to the new private registry:
#!/bin/bash
repo="<change_to_your_new_repo>"
remote_repo="<the_new_repo_name>"
for img in $(docker images --format "{{.Repository}}:{{.Tag}}")
do
image=$(echo $img | cut -d ":" -f 1)
image_tag=$(echo $img | cut -d ":" -f 2)
docker image tag $image:$image_tag $repo/$remote_repo/$image:$image_tag
docker image push $repo/$remote_repo/$image:$image_tag
docker rmi $repo/$remote_repo/$image:$image_tag
done
Upvotes: 3
Reputation: 731
Following are the steps to push Docker Image to Private Repository of DockerHub
1- First check Docker Images using command
docker images
2- Check Docker Tag command Help
docker tag --help
3- Now Tag a name to your created Image
docker tag localImgName:tagName DockerHubUser\Private-repoName:tagName
(tag name is optional. Default name is latest
)
4- Before pushing Image to DockerHub Private Repo, first login to DockerHub using command
docker login
[provide dockerHub username and Password to login]
5- Now push Docker Image to your private Repo using command
docker push [options] ImgName[:tag]
e.g docker push DockerHubUser\Private-repoName:tagName
6- Now navigate to the DockerHub Private Repo and you will see Docker image is pushed on your private Repository with name written as TagName in previous steps
Upvotes: 9
Reputation: 7633
There is also a "default privacy" setting in dockerhub. Visit https://hub.docker.com/settings/default-privacy or click account settings->default privacy.
Set the toggle to "private".
This is not a complete solution but at least private by default is better than public by default. You can go back and make the ones public you want.
Upvotes: 0
Reputation: 3939
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
Upvotes: 361
Reputation: 837
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
Upvotes: 14
Reputation: 1749
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.
Upvotes: 24
Reputation: 20565
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!
Upvotes: 4
Reputation: 121
> docker login [OPTIONS] [SERVER]
[OPTIONS]:
-u username
-p password
eg:
> docker login localhost:8080
> docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
eg:
> docker tag myApp:v1 localhost:8080/myname/myApp:v1
>docker push [OPTIONS] NAME[:TAG]
eg:
> docker push localhost:8080/myname/myApp:v1
Upvotes: 12
Reputation: 1664
If you docker registry is private and self hosted you should do the following :
docker login <REGISTRY_HOST>:<REGISTRY_PORT>
docker tag <IMAGE_ID> <REGISTRY_HOST>:<REGISTRY_PORT>/<APPNAME>:<APPVERSION>
docker push <REGISTRY_HOST>:<REGISTRY_PORT>/<APPNAME>:<APPVERSION>
Example :
docker login repo.company.com:3456
docker tag 19fcc4aa71ba repo.company.com:3456/myapp:0.1
docker push repo.company.com:3456/myapp:0.1
Upvotes: 142
Reputation: 11267
First go to your Docker Hub account and make the repo. Here is a screenshot of my Docker Hub account:
From the pic, you can see my repo is “chuangg”
Now go into the repo and make it private by clicking on your image’s name. So for me, I clicked on “chuangg/gene_commited_image”, then I went to Settings -> Make Private. Then I followed the on screen instructions
HOW TO UPLOAD YOUR DOCKER IMAGE ONTO DOCKER HUB
Method #1= Pushing your image through the command line (cli)
1) docker commit <container ID> <repo name>/<Name you want to give the image>
Yes, I think it has to be the container ID. It probably cannot be the image ID.
For example= docker commit 99e078826312 chuangg/gene_commited_image
2) docker run -it chaung/gene_commited_image
3) docker login --username=<user username> --password=<user password>
For example= docker login --username=chuangg [email protected]
Yes, you have to login first. Logout using “docker logout”
4) docker push chuangg/gene_commited_image
Method #2= Pushing your image using pom.xml and command line.
Note, I used a Maven Profile called “build-docker”. If you don’t want to use a profile, just remove the <profiles>, <profile>, and <id>build-docker</id>
elements.
Inside the parent pom.xml:
<profiles>
<profile>
<id>build-docker</id>
<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.18.1</version>
<configuration>
<images>
<image>
<name>chuangg/gene_project</name>
<alias>${docker.container.name}</alias>
<!-- Configure build settings -->
<build>
<dockerFileDir>${project.basedir}\src\docker\vending_machine_emulator</dockerFileDir>
<assembly>
<inline>
<fileSets>
<fileSet>
<directory>${project.basedir}\target</directory>
<outputDirectory>.</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
</fileSets>
</inline>
</assembly>
</build>
</image>
</images>
</configuration>
<executions>
<execution>
<id>docker:build</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Docker Terminal Command to deploy the Docker Image (from the directory where your pom.xml is located)= mvn clean deploy -Pbuild-docker docker:push
Note, the difference between Method #2 and #3 is that Method #3 has an extra <execution>
for the deployment.
Method #3= Using Maven to automatically deploy to Docker Hub
Add this stuff to your parent pom.xml:
<distributionManagement>
<repository>
<id>gene</id>
<name>chuangg</name>
<uniqueVersion>false</uniqueVersion>
<layout>legacy</layout>
<url>https://index.docker.io/v1/</url>
</repository>
</distributionManagement>
<profiles>
<profile>
<id>build-docker</id>
<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.18.1</version>
<configuration>
<images>
<image>
<name>chuangg/gene_project1</name>
<alias>${docker.container.name}</alias>
<!-- Configure build settings -->
<build>
<dockerFileDir>${project.basedir}\src\docker\vending_machine_emulator</dockerFileDir>
<assembly>
<inline>
<fileSets>
<fileSet>
<directory>${project.basedir}\target</directory>
<outputDirectory>.</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
</fileSets>
</inline>
</assembly>
</build>
</image>
</images>
</configuration>
<executions>
<execution>
<id>docker:build</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
<execution>
<id>docker:push</id>
<phase>install</phase>
<goals>
<goal>push</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Go to C:\Users\Gene.docker\ directory and add this to your config.json file:
Now in your Docker Quickstart Terminal type= mvn clean install -Pbuild-docker
For those of you not using Maven Profiles, just type mvn clean install
Here is the screenshot of the success message:
Here is my full pom.xml and a screenshot of my directory structure:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.gene.app</groupId>
<artifactId>VendingMachineDockerMavenPlugin</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Maven Quick Start Archetype</name>
<url>www.gene.com</url>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.gene.sample.Customer_View</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<distributionManagement>
<repository>
<id>gene</id>
<name>chuangg</name>
<uniqueVersion>false</uniqueVersion>
<layout>legacy</layout>
<url>https://index.docker.io/v1/</url>
</repository>
</distributionManagement>
<profiles>
<profile>
<id>build-docker</id>
<properties>
<java.docker.version>1.8.0</java.docker.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.18.1</version>
<configuration>
<images>
<image>
<name>chuangg/gene_project1</name>
<alias>${docker.container.name}</alias>
<!-- Configure build settings -->
<build>
<dockerFileDir>${project.basedir}\src\docker\vending_machine_emulator</dockerFileDir>
<assembly>
<inline>
<fileSets>
<fileSet>
<directory>${project.basedir}\target</directory>
<outputDirectory>.</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
</fileSets>
</inline>
</assembly>
</build>
</image>
</images>
</configuration>
<executions>
<execution>
<id>docker:build</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
<execution>
<id>docker:push</id>
<phase>install</phase>
<goals>
<goal>push</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Here is my Dockerfile:
FROM java:8
MAINTAINER Gene Chuang
RUN echo Running Dockerfile in src/docker/vending_machine_emulator/Dockerfile directory
ADD maven/VendingMachineDockerMavenPlugin-1.0-SNAPSHOT.jar /bullshitDirectory/gene-app-1.0-SNAPSHOT.jar
CMD ["java", "-classpath", "/bullshitDirectory/gene-app-1.0-SNAPSHOT.jar", "com/gene/sample/Customer_View" ]
Solution for Error #1= Do not sync the <execution>
with maven deploy phase because then maven tries to deploy the image 2x and puts a timestamp on the jar. That’s why I used <phase>install</phase>
.
Upvotes: 57
Reputation: 54790
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
Upvotes: 1020
Reputation: 77335
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.
Upvotes: 27