DEV Community

Kalasam Ashrith
Kalasam Ashrith

Posted on

Docker for Beginners: What Is Docker, Containerization, and Essential Commands

If you're starting your journey in DevOps, Cloud, or Kubernetes, one of the first technologies you'll come across is Docker.

When I first heard about Docker, terms like containers, images, Dockerfile, registries, and containerization made it sound more complicated than it actually is.

After working with Docker, I realized that the basic idea is quite simple:

Docker allows us to package an application along with everything it needs to run and then run that package consistently in different environments.

In this article, let's understand Docker from the beginning and then look at some of the fundamental Docker commands.

1. What is Docker?

Docker is a platform that allows us to build, package, and run applications inside containers.

But what exactly does that mean?

Imagine that you have developed a Python application on your laptop.

Your application might require:

  • Python 3.12
  • Specific Python libraries
  • Environment variables
  • Configuration files
  • Certain system dependencies

Everything works perfectly on your laptop.

Now you give the application to another developer.

They install it and run:

python app.py
Enter fullscreen mode Exit fullscreen mode

And they get:

ModuleNotFoundError
Enter fullscreen mode Exit fullscreen mode

Why?

Because their environment is different.

Maybe they have a different Python version. Maybe a required library is missing. Maybe some system dependency isn't installed.

This is where Docker becomes useful.

Instead of giving someone only your application, you can package the application together with its required environment into a Docker image.

That image can then be used to create a container.


2. What Problem Does Docker Solve?

A common problem in software development is:

"It works on my machine."

Developers may have different:

  • Operating systems
  • Programming language versions
  • Libraries
  • Dependencies
  • Configurations
  • Environment variables

Docker helps reduce these environment differences by providing a consistent way to package and run applications.

For example:

Developer Laptop
       |
       v
    Docker
       |
       v
   Container
       |
       +---- Application
       +---- Dependencies
       +---- Required runtime
Enter fullscreen mode Exit fullscreen mode

The same image can then be used in different environments.

Developer Machine
       |
       v
     Docker
       |
    Container
       |
       v
     App


Test Server
       |
       v
     Docker
       |
    Container
       |
       v
     App


Cloud Server
       |
       v
     Docker
       |
    Container
       |
       v
     App
Enter fullscreen mode Exit fullscreen mode

The goal is to make the application environment much more predictable.


3. What is Containerization?

Before understanding Docker deeply, we need to understand containerization.

Containerization is the practice of packaging an application together with the things it needs to run into an isolated environment called a container.

Think of a container like a lightweight box containing your application.

For example:

+--------------------------------+
|          Container             |
|                                |
|   My Application               |
|                                |
|   Dependencies                 |
|                                |
|   Runtime                      |
|                                |
|   Configuration                |
+--------------------------------+
Enter fullscreen mode Exit fullscreen mode

The application runs inside this isolated environment.

Docker provides the tools and platform that make creating and running these containers easy.


4. Docker Container vs Virtual Machine

A common question when learning Docker is:

"Is a Docker container the same as a virtual machine?"

No.

A virtual machine includes an entire guest operating system.

For example:

Physical Server
|
+-- VM 1
|    |
|    +-- Guest OS
|    +-- Application
|
+-- VM 2
     |
     +-- Guest OS
     +-- Application
Enter fullscreen mode Exit fullscreen mode

Containers work differently.

Containers share the host operating system's kernel while keeping applications isolated from each other.

Physical Server
|
+-----------------------------+
|        Host OS              |
|                             |
| +---------+   +---------+   |
| |Container|   |Container|   |
| |   App 1 |   |   App 2 |   |
| +---------+   +---------+   |
|                             |
+-----------------------------+
Enter fullscreen mode Exit fullscreen mode

Because containers don't need a separate complete guest OS for each application, they are generally much lighter and faster to start than traditional VMs.


5. What is a Docker Image?

A Docker image is a packaged, read-only template used to create containers.

You can think of an image as a blueprint.

For example:

Docker Image
     |
     | creates
     v
Docker Container
Enter fullscreen mode Exit fullscreen mode

If you have an Nginx image, you can create a container from it.

nginx image
     |
     +------> Container 1
     |
     +------> Container 2
     |
     +------> Container 3
Enter fullscreen mode Exit fullscreen mode

The same image can be used to create multiple containers.


6. What is a Docker Container?

A container is a running instance of a Docker image.

For example:

docker run nginx
Enter fullscreen mode Exit fullscreen mode

Docker will use the nginx image to create and start a container.

A simple way to remember this is:

Image = blueprint
Container = running instance created from that blueprint

Similar to:

Class  → Object
Image  → Container
Enter fullscreen mode Exit fullscreen mode

This isn't a perfect technical analogy, but it's useful when you're learning the concept.


7. What is a Dockerfile?

Now comes another important concept: the Dockerfile.

A Dockerfile contains instructions that Docker uses to build an image.

For example:

FROM nginx

COPY index.html /usr/share/nginx/html/index.html
Enter fullscreen mode Exit fullscreen mode

Here:

FROM nginx
Enter fullscreen mode Exit fullscreen mode

means we're starting with the Nginx image.

And:

COPY index.html /usr/share/nginx/html/index.html
Enter fullscreen mode Exit fullscreen mode

copies our HTML file into the image.

We can then build an image:

docker build -t my-nginx .
Enter fullscreen mode Exit fullscreen mode

And run it:

docker run my-nginx
Enter fullscreen mode Exit fullscreen mode

So the basic flow is:

Dockerfile
     |
     | docker build
     v
Docker Image
     |
     | docker run
     v
Docker Container
Enter fullscreen mode Exit fullscreen mode

This is one of the most important workflows to understand when learning Docker.


8. Docker Registry

Where do Docker images come from?

One common source is a container registry.

A registry is a place where container images can be stored and shared.

One of the most popular public registries is Docker Hub.

For example, you can find images such as:

nginx
redis
postgres
mysql
ubuntu
python
node
Enter fullscreen mode Exit fullscreen mode

When you run:

docker pull nginx
Enter fullscreen mode Exit fullscreen mode

Docker downloads the Nginx image from a registry.

Then you can run it:

docker run nginx
Enter fullscreen mode Exit fullscreen mode

The overall flow looks like:

Docker Registry
       |
       | docker pull
       v
Docker Image
       |
       | docker run
       v
Docker Container
Enter fullscreen mode Exit fullscreen mode

9. Fundamental Docker Commands

Now let's get practical.

You don't need to memorize hundreds of Docker commands initially.

Start with these fundamental commands.


9.1 Check Docker Version

docker --version
Enter fullscreen mode Exit fullscreen mode

Example:

Docker version 28.x.x
Enter fullscreen mode Exit fullscreen mode

You can also use:

docker version
Enter fullscreen mode Exit fullscreen mode

The second command provides more detailed information.


10. Download an Image

Use:

docker pull nginx
Enter fullscreen mode Exit fullscreen mode

This downloads the Nginx image from the configured registry.

You can also specify a version:

docker pull nginx:1.27
Enter fullscreen mode Exit fullscreen mode

Here:

nginx       → image name
1.27        → image tag/version
Enter fullscreen mode Exit fullscreen mode

If you don't specify a tag, Docker generally uses the latest tag.


11. List Docker Images

After downloading an image:

docker images
Enter fullscreen mode Exit fullscreen mode

You'll see something similar to:

REPOSITORY   TAG       IMAGE ID       SIZE
nginx        latest    abc123         192MB
Enter fullscreen mode Exit fullscreen mode

This shows the images available locally.


12. Run a Container

The most important command:

docker run nginx
Enter fullscreen mode Exit fullscreen mode

This tells Docker:

Create a container from the Nginx image and start it.

Docker will:

  1. Check whether the image exists locally.
  2. Download it if necessary.
  3. Create a container.
  4. Start the container.

13. Run a Container in the Background

By default:

docker run nginx
Enter fullscreen mode Exit fullscreen mode

runs the container attached to your terminal.

To run it in the background:

docker run -d nginx
Enter fullscreen mode Exit fullscreen mode

The -d means:

detached mode

The container continues running in the background.


14. Give a Container a Name

You can assign a name using:

docker run -d --name my-nginx nginx
Enter fullscreen mode Exit fullscreen mode

Now the container is called:

my-nginx
Enter fullscreen mode Exit fullscreen mode

This makes it easier to manage.

For example:

docker stop my-nginx
Enter fullscreen mode Exit fullscreen mode

instead of having to remember a container ID.


15. List Running Containers

Use:

docker ps
Enter fullscreen mode Exit fullscreen mode

Example:

CONTAINER ID   IMAGE   COMMAND   STATUS
abc123         nginx   ...       Up 2 minutes
Enter fullscreen mode Exit fullscreen mode

This shows currently running containers.


16. List All Containers

What if a container has stopped?

docker ps won't show it.

Use:

docker ps -a
Enter fullscreen mode Exit fullscreen mode

The -a means all containers, including stopped containers.


17. Stop a Container

To stop a running container:

docker stop my-nginx
Enter fullscreen mode Exit fullscreen mode

Docker sends a stop request to the container and allows it to shut down gracefully.


18. Start a Stopped Container

If a container already exists but is stopped:

docker start my-nginx
Enter fullscreen mode Exit fullscreen mode

Notice the difference:

docker run
Enter fullscreen mode Exit fullscreen mode

creates a new container from an image.

docker start
Enter fullscreen mode Exit fullscreen mode

starts an existing container.

This distinction is important.


19. Restart a Container

You can restart a container with:

docker restart my-nginx
Enter fullscreen mode Exit fullscreen mode

20. Remove a Container

To delete a stopped container:

docker rm my-nginx
Enter fullscreen mode Exit fullscreen mode

You can also remove a running container using:

docker rm -f my-nginx
Enter fullscreen mode Exit fullscreen mode

Be careful with -f because it forcefully removes the container.


21. View Container Logs

One of the most useful troubleshooting commands is:

docker logs my-nginx
Enter fullscreen mode Exit fullscreen mode

If the application inside the container is producing logs, this command lets you see them.

You can also follow logs:

docker logs -f my-nginx
Enter fullscreen mode Exit fullscreen mode

The -f means follow.


22. Execute a Command Inside a Container

Sometimes you need to get inside a running container.

For example:

docker exec -it my-nginx /bin/bash
Enter fullscreen mode Exit fullscreen mode

If Bash isn't available, you might use:

docker exec -it my-nginx /bin/sh
Enter fullscreen mode Exit fullscreen mode

The important part is:

docker exec
Enter fullscreen mode Exit fullscreen mode

It allows you to execute a command inside an already running container.


23. Port Mapping

Here's an important concept.

Suppose Nginx is running inside a container on port 80.

That doesn't automatically mean you can access it through your host's port 80.

You can map a host port to the container port:

docker run -d --name my-nginx -p 8080:80 nginx
Enter fullscreen mode Exit fullscreen mode

The format is:

-p HOST_PORT:CONTAINER_PORT
Enter fullscreen mode Exit fullscreen mode

So:

8080:80
Enter fullscreen mode Exit fullscreen mode

means:

Host port 8080
       |
       v
Container port 80
Enter fullscreen mode Exit fullscreen mode

You can then access Nginx through:

http://localhost:8080
Enter fullscreen mode Exit fullscreen mode

24. View Container Details

Use:

docker inspect my-nginx
Enter fullscreen mode Exit fullscreen mode

This provides detailed information about the container, including things such as:

  • Network configuration
  • Mounts
  • Environment
  • Container configuration
  • IP information
  • Runtime settings

It's extremely useful when troubleshooting.


25. A Small Docker Practice

Let's put some of these commands together.

First download Nginx:

docker pull nginx
Enter fullscreen mode Exit fullscreen mode

Run it:

docker run -d --name my-nginx -p 8080:80 nginx
Enter fullscreen mode Exit fullscreen mode

Check that it's running:

docker ps
Enter fullscreen mode Exit fullscreen mode

Open:

http://localhost:8080
Enter fullscreen mode Exit fullscreen mode

You should see the Nginx welcome page.

Check the logs:

docker logs my-nginx
Enter fullscreen mode Exit fullscreen mode

Enter the container:

docker exec -it my-nginx /bin/bash
Enter fullscreen mode Exit fullscreen mode

Exit:

exit
Enter fullscreen mode Exit fullscreen mode

Stop the container:

docker stop my-nginx
Enter fullscreen mode Exit fullscreen mode

Start it again:

docker start my-nginx
Enter fullscreen mode Exit fullscreen mode

Finally remove it:

docker stop my-nginx
docker rm my-nginx
Enter fullscreen mode Exit fullscreen mode

This small exercise gives you hands-on experience with the basic Docker lifecycle.


26. Docker's Basic Architecture

At a high level, you can think about Docker like this:

                 Docker Registry
                       |
                       | pull
                       v
                +-------------+
                | Docker Image|
                +-------------+
                       |
                       | run
                       v
                +-------------+
                |  Container  |
                +-------------+
                       |
                       v
                  Application
Enter fullscreen mode Exit fullscreen mode

And when you create your own application:

             Dockerfile
                  |
                  | docker build
                  v
            Docker Image
                  |
                  | docker run
                  v
             Container
                  |
                  v
             Application
Enter fullscreen mode Exit fullscreen mode

Understanding these two flows will make many other Docker concepts easier later.


27. Why is Docker Important for DevOps?

Docker became extremely important in DevOps because it makes application packaging and deployment more consistent.

A typical workflow might look like:

Developer
    |
    | writes code
    v
Dockerfile
    |
    | docker build
    v
Docker Image
    |
    | push
    v
Container Registry
    |
    | pull
    v
Server
    |
    | docker run
    v
Container
Enter fullscreen mode Exit fullscreen mode

This fits naturally into CI/CD pipelines.

For example:

Code Change
     |
     v
CI Pipeline
     |
     v
Build Docker Image
     |
     v
Test Image
     |
     v
Push Image
     |
     v
Deploy
Enter fullscreen mode Exit fullscreen mode

This is one reason Docker is such an important technology to understand if you're moving toward DevOps.


28. Docker and Kubernetes

If you're learning Kubernetes, understanding Docker concepts is still very useful.

Kubernetes manages containers, but Kubernetes itself is not simply "Docker."

Modern Kubernetes clusters use a container runtime such as containerd or CRI-O.

So think about the relationship like this:

Docker
   |
   | helps you build/package/run containers
   v
Container Image
   |
   v
Container Runtime
   |
   v
Kubernetes
   |
   v
Manages containers across multiple machines
Enter fullscreen mode Exit fullscreen mode

Docker concepts such as:

  • Images
  • Containers
  • Registries
  • Container networking
  • Volumes
  • Environment variables

are foundational concepts that will help you understand Kubernetes.


29. Docker Commands Cheat Sheet

Here are the commands worth practicing first:

Command Purpose
docker --version Check Docker version
docker pull nginx Download an image
docker images List images
docker run nginx Create and run a container
docker run -d nginx Run in background
docker ps List running containers
docker ps -a List all containers
docker stop <container> Stop a container
docker start <container> Start a stopped container
docker restart <container> Restart a container
docker rm <container> Remove a container
docker logs <container> View logs
docker exec -it <container> /bin/sh Execute a command inside container
docker inspect <container> View detailed container information
docker build -t <name> . Build an image
docker push <image> Push an image to a registry

Don't try to memorize all of these immediately.

Practice them.

The commands will become familiar naturally.


30. Final Thoughts

Docker can look complicated when you first encounter terms like images, containers, Dockerfiles, registries, volumes, networks, and containerization.

But the fundamental idea is straightforward:

Build an image → create a container → run your application.

The basic workflow is:

Application
     |
     v
Dockerfile
     |
     | docker build
     v
Docker Image
     |
     | docker run
     v
Docker Container
     |
     v
Running Application
Enter fullscreen mode Exit fullscreen mode

Once this workflow becomes clear, you can start learning more advanced Docker concepts such as:

  • Docker volumes
  • Docker networks
  • Environment variables
  • Multi-stage builds
  • Docker Compose
  • Image optimization
  • Container security
  • Private registries
  • CI/CD with Docker
  • Docker and Kubernetes

Docker is not just another tool to memorize for a DevOps interview. The important thing is to understand why containers exist, how images become containers, and how Docker fits into the software delivery process.

That's the foundation on which many modern DevOps and Kubernetes workflows are built.

Top comments (1)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.