Set a tag for this image as “localhost:5000
“.
Why are we tagging like that?
It’s because the registry is created locally and it runs on port 5000.
I have tagged it as localhost:5000/database
because it’s a database image.
[email protected]:~$ docker push localhost:5000/database
Using default tag: latest
The push refers to repository [localhost:5000/database]
750644870eed: Pushed
354cd4440aa7: Pushed
96789aa73d8f: Pushed
956b4f80a078: Pushed
df8b8ee18301: Pushed
7e50f83cc60c: Pushed
b98c96f5ae6b: Pushed
b699e149afa6: Pushed
0552d4cbc6e9: Pushed
a70daca533d0: Pushed
latest: digest: sha256:84075fa0ee8106f8e2975dca79d3c6f9587b41afefa7aec57e76a2fc9506df6c size: 2412
We have pushed the image to our local registry. The most beautiful part is that if we remove the image locally from the machine, we’ll still be able to pull it again from the local repository.
That’s how an image is removed with the docker rmi
command which stands for remove image.
[email protected]:~$ docker rmi localhost:5000/database:latest
Untagged: localhost:5000/database:latest
Untagged: localhost:5000/[email protected]:84075fa0ee8106f8e2975dca79d36a2fc9506df6c
We have removed the image from the machine locally.
Now let’s pull the same image from the local repository we created to see if it works.
[email protected]:~$ docker pull localhost:5000/database
Using default tag: latest
latest: Pulling from database
Digest: sha256:84075fa0ee8106f8e2975dca79d3c6f9587b41afefa7aec57e76a2fc9506df6c
Status: Downloaded newer image for localhost:5000/database:latest
localhost:5000/database:latest
Boom!
We have pulled the image from our local repository with the docker pull
command.
I have confirmed it on my Ubuntu machine running the docker images
command.
[email protected]:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
localhost:5000/database latest f55fb7cb2f36 2 days ago 409MB
So, having a local repository is a good idea to keep images locally. I would strongly recommend you guys to create one on your system and try to pull and push images locally.