Introduction
Basically, this article has a connection with the previous article focusing on how to run a local docker repository. So, since the local docker repository is running, it is available for further usage. One of the usage is to push a certain docker image. For an example if there is a requirement to get an image only from a local docker repository without having to connect to the internet. Just connect it once to the internet to get or to pull the docker image from a public docker repository. After that, just push it to the local docker repository. Next time, if there is a need to get that docker image, just get it from the local docker repository without having to connect to the internet and without having to get it from the public docker repository.
Push a Docker Image to a Local Docker Repository
This is the step for pushing a docker image to a local docker repository in an order manner :
-
First of all, just make sure that the image is available. In this context, it is the image which is going to be pushed to the local private registry repository. Just execute the following command to list the available image :
C:\mydocker-build>docker image list --all REPOSITORY TAG IMAGE ID CREATED SIZE mydockerapp latest e1d4421cfe4b 18 hours ago 1.04GB docker101tutorial latest 7f8109362ad3 3 weeks ago 28.5MB hub.docker.local:5000/local-alpine latest c059bfaa849c 5 weeks ago 5.59MB alpine/git latest c6b70534b534 6 weeks ago 27.4MB registry latest b8604a3fe854 7 weeks ago 26.2MB hello-world latest 22773018c042 3 months ago 231MB C:\mydocker-build>
-
Following after, select the image which is going to be pushed. For an example, it is an image with the name of ‘hello-world’. Just tag the image by executing a specific command. In this context, the tag name consist of the local private registry repository name. For an example, in this article it is using ‘hub.docker.local:5000’. Actually, it is a local private registry repository with the IP address of 127.0.0.1 and it is running on port 500. So, execute the following command in order to tag the image :
C:\mydocker-build>docker tag hello-world hub.docker.local:5000/hello-world C:\mydocker-build>
-
Check the image list once more by typing the previous command as follows :
C:\mydocker-build>docker image list --all REPOSITORY TAG IMAGE ID CREATED SIZE mydockerapp latest e1d4421cfe4b 18 hours ago 1.04GB docker101tutorial latest 7f8109362ad3 3 weeks ago 28.5MB hub.docker.local:5000/local-alpine latest c059bfaa849c 5 weeks ago 5.59MB alpine/git latest c6b70534b534 6 weeks ago 27.4MB registry latest b8604a3fe854 7 weeks ago 26.2MB hello-world latest 22773018c042 3 months ago 231MB hub.docker.local:5000/hello-world latest 22773018c042 3 months ago 231MB C:\mydocker-build>
-
Last but not least, just execute the following command to push the tagged image of ‘hub.docker.local:5000’ to the local private registry repository as follows :
C:\mydocker-build>docker push hub.docker.local:5000/hello-world Using default tag: latest The push refers to repository [hub.docker.local:5000/hello-world] 74ddd0ec08fa: Pushed latest: digest: sha256:871437a0111c0923655353aa66a284b43b48bcbfd0c9038c9116a5f187805dab size: 529 C:\mydocker-build>
-
In order to check whether the image exist in the local private registry repository, just execute the following command :
C:\mydocker-build>curl hub.docker.local:5000/v2/_catalog {"repositories":["centos","hello-world","local-alpine"]} C:\mydocker-build>
One thought on “How to Push a Docker Image to a Local Docker Repository”