DEV Community

Cover image for A Docker Not So Quick Start 🐋 - Baby Steps
LĂșcio Ewald
LĂșcio Ewald

Posted on

2 1 1 1 1

A Docker Not So Quick Start 🐋 - Baby Steps

Hey everyone! In this post, I’ll give you a brief introduction to Docker, but I won’t focus on installation. There are already plenty of tutorials out there that cover how to set up Docker on your OS, so that’s not the focus here.

Instead, the goal of this post is to:

  1. Help you understand what is Docker.
  2. The problem it solves.
  3. Concepts of a Docker application.
  4. Walk you through the basic Docker commands and get a simple Nginx server up and running.

So What is Docker? đŸ€”

Let’s start with what Docker is not. Docker is not a Virtual Machine (VM). While it’s common to compare Docker to a VM because it helps us grasp its functionality, in reality, Docker is just a process running on your machine. Nowadays, Docker is more of an ecosystem made up of many tools and software, such as:

  • Docker Engine – The core software behind the entire solution. It’s both the daemon responsible for containers and the client used to send commands to the daemon.
  • Docker Compose – A tool used to define and manage multi-container applications based on configuration files.

I didn’t mention Docker Machine or Docker Swarm, as they’re not aligned with the focus of this post, but feel free to look them up if you're interested.

The Problem it Solves? đŸ€š

We can say that the same Java philosophy of "Write Once, Run Anywhere" applies to Docker, but with a slight tweak. In Docker’s case, it’s more like "Build Once, Run Anywhere."

Why? Because with Docker, you package your entire application—including the code, dependencies, and environment—into a container. Keep in mind, we’re still going to talk about containers, images, and other Docker concepts in the next section. This ensures that your app runs exactly the same way on different machines, regardless of the operating system or underlying setup. No more "it works on my machine" issues!

Before Docker... đŸ˜”

Developers had to manually install dependencies, set up environments, and deal with compatibility problems across different OSes. Moving an app from development to production could be a nightmare.

Other Solutions That Came Before đŸ› ïž

There were tools that tried to solve these issues:

  • Virtual Machines (VMs) – Provided isolation but were resource-heavy and slow.
  • Vagrant – Helped manage environments with lightweight VMs but still relied on virtualization.
  • Configuration Management Tools (Ansible, Chef, Puppet) – Automated setup but didn’t fully isolate dependencies.
  • LXC (Linux Containers) – Introduced containerization but lacked Docker’s ease of use and developer-friendly tooling.

Docker simplified everything by making containerization efficient, portable, and easy to use.

Some Docker Concepts ⚓

Images đŸ–Œïž

Think of images as blueprints for your application. They contain everything needed to set up and run your app, including the OS, dependencies, and configurations. You can download pre-built images from repositories like Docker Hub, GitHub Container Registry, or Google Container Registry. Or, if you need something custom, you can build your own image with everything your app requires, using a Dockerfile as a recipe.

Containers 📩

If an image is the blueprint, then a container is the actual running instance of that blueprint. Containers are lightweight, portable, and isolated environments where your application runs. You can spin them up, stop them, and remove them with simple commands.

Dockerfile 📜

Is a text file that contains instructions to build a custom Docker image. It defines the base image, the dependencies to install, and the commands to run. It’s like a recipe for creating your app’s environment in a Docker container.

Lets Cook 🍳

Finally, let’s get into action! In this section, we’ll download an Nginx image, run it, and do some fun testing.

First, let’s check if Docker is correctly installed on your OS by running:

docker -v
Enter fullscreen mode Exit fullscreen mode

If you're on Linux like me and haven’t added Docker to the user group, you might need to run the command with sudo privileges.

The output should look something like this (though it may vary depending on your version):

docker version

Now that we’ve confirmed Docker is installed correctly, let's check which images we may already have on our machine. To do this, run:

docker image list
Enter fullscreen mode Exit fullscreen mode

This will display a list of all the images available. Here’s an example from my setup:

listing images

As you can see, I don’t have any images on my machine right now, but not for long! Let’s download the Nginx image using the following command:

docker pull nginxdemos/hello
Enter fullscreen mode Exit fullscreen mode

listing images details

In the image above, we see Docker layers in action—one of Docker's greatest advantages. We'll dive deeper into this in a future post, but feel free to look it up in the meantime!

Now, when we list the local images again, we get the following result.

listing images content

Nice! Now that we already have our Nginx image locally, we can run it and see it in action as a container. Technically, we could just run docker container run nginxdemos/hello. But that wouldn’t be much fun because we wouldn’t be able to access the running Nginx server from our machine. This happens because, by default, Docker containers are isolated from the host.

To make things more interesting, we’ll add some parameters when running the command to properly expose the container’s port and interact with it.

Now, let’s run:

docker container run -it --rm -p 8080:80 nginxdemos/hello
Enter fullscreen mode Exit fullscreen mode

Here’s a quick explanation of the parameters used in the command.

Parameter Description
-i Runs the container in interactive mode, allowing user input.
-t Allocates a pseudo-TTY (terminal), making it behave like a regular terminal session.
--rm Automatically removes the container once it stops, preventing clutter.
-p 8080:80 Maps port 80 inside the container to port 8080 on the host, allowing access from the browser.

And now if we visit http://localhost:8080/ we will see the Nginx Hello World page :)

webpage default

Yeah, that’s nice and all, but it could be even more fun! Let’s create our own HTML file and make Nginx serve it instead of the default page.

To do this, just run the following commands on Linux:

mkdir -p ~/tst && echo '<h1>Hello Docker</h1>' > ~/tst/index.html
Enter fullscreen mode Exit fullscreen mode

This will create a file called index.html inside the a tst folder in your home directory (~/).

Now, let's run:

docker container run -it --rm -p 8080:80 -v ~/tst:/usr/share/nginx/html nginxdemos/hello
Enter fullscreen mode Exit fullscreen mode

In the command above, we created a volume between our host machine and the Docker container running Nginx using the -v parameter. Now, if we visit http://localhost:8080 again, we will see the "Hello Docker" message.

webpage custom

So that’s it for now, guys! I know you may have many questions about Docker, volumes, Dockerfiles, how to create our own images, more details about all the parameters we can use when initializing a container, how to manage running containers, and more. We’ll cover all these topics in future posts. This one was just a way for us to dip our toes in the water. Please feel free to drop your comments below—questions and feedback are always welcome!

Talk to you soon! đŸ«¶

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

đŸ‘„ Ideal for solo developers, teams, and cross-company projects

Learn more