5- Docker: Pushing and Pulling Images To Docker Registry - Cleaning Up Our Workspace From Old Images and Containers

Docker Registry is a Highly Scalable server side application that stores and let you distribute Docker images. Docker registry also can be used for CD/CI Pipeline. You can also run your containers on Docker Registry. Docker Regisrty can be public or private. Most popular Docker registries are: Docker Hub, QUAY.IO, Amazon ECR.

We will be using DockerHub. Go ahead and create a free account at https://hub.docker.com 

 

PUSHING:

Log in DockerHub > Repositories> Create Repository > Give a name to your repository > Click Create button

Note that my namespace is selimica and repo name is website.

 

Now I need to tag my docker images according to my repository name. So new tag has my docker account name and tag like below

docker tag mycustomimage:v1 selimica/website:v1

docker tag mycustomimage:v2 selimica/website:v2

 

To push my local images, First I need to login to dockerhub on my Terminal by using dockerhub username and password, then I can use push command.

docker login

 

 

Both images successfully pushed to my repository

 

PULLING:

If you need to download a docker image from dockerhub you can use pull command like this:

docker pull <namespace>/<repo-name>:<version>

 

So far, we have used docker while creating docker containers. In the upcoming articles we are going to use Docker Compose Tool. Docker Compose is used for running multiple containers as a single service. Containers still will be isolated but can interact with each other. Before we work with docker compose, I want to clean up my workspace from all images and containers .

 

Cleaning Up Our Workspace:

So far, we have pulled many images and created many containers on our host machine. Run the command below to see all the containers we have on our system (running and not running containers)

docker ps -a

If I run the same command like this, I will get container ids only

docker ps -aq

Which means I can pass the command above as an argument to my remove command like below

docker rm -f $(docker ps -aq)

Now if I run docker ps -a command again, I see all the containers on my system are gone. You can remove all docker images with the command below by using the same logic if you want to.

docker image rm -f $(docker images -aq)

 

Now docker images -a returns nothing.