How to test images from DockerHub ?

Author
By Darío Rivera
Posted On in Docker

Before starting we recommend you to read our post Hello world in Docker, surely it will be a good start if you are still starting in this world of Docker. In this post, we will see how to test Docker images, that is, we will see how to quickly mount containers of the most important images such as Debian, Alpine, or the one you require.

The first thing you should do is identify the Docker image you want to test, for this you can go to Docker Hub. Once you have identified the image, it is time to create a new container from this image. With the docker run command, you can achieve this.

Container Creation

Let's see, for example, how to create a container from a GNU/Linux Debian Buster image. Note that we have used the --name parameter to give the container a name and the --detach parameter so that the container continues to run in the background and does not end its execution (this will allow us to enter the shell of the distro together with --tty).

docker run --detach --tty --name debian-buster debian:buster

If the image is not on your machine, which is most likely, it will be downloaded immediately. From this, you will get output similar to the following:

user@server# docker run --detach --tty --name debian-buster debian:buster
Unable to find image 'debian:buster' locally
buster: Pulling from library/debian
ccd458f933f7: Pull complete 
Digest: sha256:fde7a280413ec0122bd3a14dc76ba152f89cae999f3b8efe8784100df3640763
Status: Downloaded newer image for debian:buster
df5cba273b5ba5a75875b6b58e87e7e6c67b9ab93abb87a918991c4f29bf114b

You can simplify the previous command as follows:

docker run -dt --name debian-buster debian:buster

Entering the Shell and Executing Commands

Once this is done, you can enter the container shell with docker exec.

docker exec -it debian-buster bash

The -t parameter places you in a shell and the -i parameter allows the shell to be interactive, that is, you can execute commands and see their response.

It should be noted that you can also execute commands without using an interactive shell. Many times you need the output of that command in your local system shell. For this, you can omit the -it parameters.

user@server# docker exec debian-buster date
Sat Jan 29 04:31:05 UTC 2022

Executing Commands in Containers without detach

If you want to try a very specific command on a container that is not running in the background forever, you can execute the following command.

docker run -it debian:buster /bin/bash

This way you will directly stay in the system shell and can test whatever you want. Once you close that shell the container will end its execution (because it does not have the --detach parameter).

Conclusion

This way you can download and test almost any image you want from Docker Hub. Do not forget to like if you liked this article. See you next time!


Acerca de Darío Rivera

Author

Application Architect at Elentra Corp . Quality developer and passionate learner with 10+ years of experience in web technologies. Creator of EasyHttp , an standard way to consume HTTP Clients.

LinkedIn Twitter Instagram

Sólo aquellos que han alcanzado el éxito saben que siempre estuvo a un paso del momento en que pensaron renunciar.