DEV Community

Mohammad Reza Karimi
Mohammad Reza Karimi

Posted on • Updated on

How docker will save your time, and why should you learn it immediately. (1/2)

What is Docker? And why is it popular?
Everywhere on the internet you find articles about how docker is compared with VM and diagrams like this:

Docker VS VM

But I'm going to teach you Docker just as a tool, so it will be so easier to understand, and we don't dissect it's underlying functionality a lot (we do it just a few πŸ˜…).

Don't install new apps! just pull them!

The most interesting thing about docker for a beginner, is the ability to pull different tools so easily.
DockerHub will be like the App Store!

Docker app store!

As you see, we can pick up any app that we want, actually we call them images in the world of Docker.

What is an image?

Image is a collection of applications and commands running on a base image and this base image itself is a simplified Linux distro.
This Linux doesn't have a GUI and could be any distro such as Ubuntu, Alpine, Bullseye, etc.

For example, you can install almost any version of any database such as Postgres, Redis, etc, by pulling their image and run them as a container.
You can have multiple versions of the same application at the same time.

What is a container?

Image itself can be supposed as an executable file, it is nothing unless you run it, anytime you run it, a container (process) will be made.
you can run many same containers using an image.

Getting dirty with Redis!

Let's have a hands-on experience with Redis,
Go to this link

Redis dockerhub

In this picture,
Tags can be assumed as different version of images, tag name may include base image name and its version.

Official images are famous projects that are being made constantly by docker team, actually everyone including you and me, can make an image and push it on Dockerhub as a public or private docker image.

At the top right, you can see docker pull redis command, it's the simplest way to pull this image, but we can find more detailed commands at the bottom of that page.

For example this command will pull the redis image and run a container called "my-redis-container":

docker run --name my-redis-container -d redis
Enter fullscreen mode Exit fullscreen mode

-d is used for detaching the process, it will run this container and leave the shell alone for your future use.

But you're not able to use this container, you should expose the Redis port.

docker run --name my-redis-container -p 6379:6379 -d redis
Enter fullscreen mode Exit fullscreen mode

-p 6379:6379 is a port mapping that maps port 6379 of the container to the 6379 of our localhost.
And you can now access Redis through localhost:6379

What other things can I do?

  • Are you a windows user but you like to use Linux without getting into the trouble of VM or Double boot? Run this command:
docker run --name itubu -it ubuntu
Enter fullscreen mode Exit fullscreen mode

This will make a container named "itubu" and connect your shell to its shell.
running ubuntu in docker

the "run" command, first look in your local to see if there is any image called "ubuntu", then if it doesn't exists, docker will pull it from Dockerhub.

  • Do you want to use Tor network without getting into the trouble of configuring tor? Run this command:
sudo docker run -p 8118:8118 -p 9050:9050 -d dperson/torproxy
Enter fullscreen mode Exit fullscreen mode

dperson/torproxy is an unofficial docker image.

-p 8118:8118 (and -p 9050:9050) is a port mapping that maps port 8118 of container to the 8118 of our localhost.

Now you can proxy your requests through Tor network using this ports.

  • Do you want to use a headless browser? Run this command
docker run -p 3000:3000 browserless/chrome
Enter fullscreen mode Exit fullscreen mode

And you'll have a chrome browser on localhost:3000
It could be so helpful for scrapping.

  • We spoke about databases before πŸ˜„ and there are so many other usecases.

It mostly needs no effort

Docker itself plays an important role in DevOps world, and without a doubt, it has so many tips and tricks.
But in most cases, as a beginner, you will just need a one line command or a 10 line Dockerfile, to make your project way much better.
The advantages of using Docker is explained in a video I added to the end of this article and I'm not covering them.

Other resources

There are so many tutorials out there, but I'm gonna suggest the ones that I enjoyed the most.
As an instruction that show how containerization will help us: Containerization explained
Docker and Kubernetes course by Stephan Grider

Final quote

I tried to help you understand that docker is not a challenge, it's a tool to make your life easier, this part included some cool stuff, next part we will cover basics of writing a Dockerfile and how to make your custom images.

Next Part: How docker will save your time, and why should you learn it immediately. (2/2)

Top comments (1)

Collapse
 
mezzir profile image
Mobina Ezzoddin

Great post, thank you