docker-primer-contenedor-sin-instalar-nada

Understanding Docker in 5 Minutes (Without Installing Anything)

  • 3 min

One of the biggest doubts when you start with Docker is understanding exactly what it’s for and what real utility it has in your daily life.

Theory is great, but the best way to understand it is to see it in action with a practical example.

That’s why, in this article, we’re going to start from the roof down and try to see Docker in operation, without installing anything on your computer.

Instead of sending you to external pages or having you start installing things, I’ve included simulated interactives in this article.

They mimic the behavior of a real Docker environment, so you can see it working without having to install anything. With just one command!

The Classic Hello World

Let’s start with the basics to check everything works, by printing a Hello World to the terminal.

Imagine this is your computer’s terminal, with Docker installed (click “Run”):

You’ll see that our simulated Docker:

Says it can’t find the image locally.

Then downloads it, and responds with a text message explaining what happened.

Shows Hello World in your console.

Good, it works. This is the usual way to verify Docker is installed correctly on the system.

But let’s be honest: this doesn’t impress anyone. Let’s go for something real and useful.

Spinning Up a Web Server in 3 Seconds

Now things get interesting. Imagine you need an Nginx web server to host a static page.

If you did it the old-fashioned way, you’d have to:

  1. Figure out how to install Nginx on your Linux distribution.
  2. Run apt-get install nginx or yum install...
  3. Configure permissions.
  4. Start the service.
  5. Pray it doesn’t conflict with another service on port 80.

With Docker, we do it like this (hit “Run”).

Congratulations! You just deployed a functional, isolated, and operational web service in seconds.

What Just Happened?

Let’s briefly analyze the command we just ran, although we’ll delve into each part later in the course.

docker run -d -p 80:80 nginx

  • docker run: The command to create and start a container.
  • nginx: This is the name of the Image. Docker looked on your machine, saw you didn’t have it, went to Docker Hub, downloaded the latest official version of Nginx, and used it.
  • -d: Tells the container to run in the “background” (Detached). If we didn’t put this, the web server would block our terminal.
  • -p 80:80: We are telling it to connect port 80 of the host machine with port 80 inside the container (Port Publishing). This is what allows us to see the web page from the outside.

Cleaning Up the Mess

One of the best things about Docker is how easy it is to clean up. If you had installed Nginx natively, uninstalling it sometimes leaves leftovers.

In Docker, we simply destroy the container.

  1. See what containers you have running:

You’ll see a line with your Nginx and a weird ID, like a1b2c3d4...

  1. Kill the container (using the first 3 characters of the ID is enough, e.g., a1b):

Poof! The container has been removed. Port 80 is free again and your system is exactly as clean as it was before you started reading this article.