I have a docker images 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?
Just three simple steps:
docker login --username username --password password
docker tag my-image username/my-repo
docker push username/my-repo
If you docker registry is private and self hosted you should do the following :
Example :
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=gc.genechaung@gmail.com
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:
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:
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:
Here is my Eclipse Directory:
Here is my Dockerfile:
Common Error #1:
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>
.