Absolute beginner's guide to Docker: What is a container?

Absolute beginner's guide to Docker: What is a container?

12 mins read
Jun 24, 2021
Share
editor-page-cover
Content
What is Docker?
What are containers?
Docker modules
Docker Compose
Docker Machine
Docker stack
Docker swarm
Dockerfile Best Practices and Multistage Builds
Key tips for effective Dockerfiles
Docker vs Kubernetes
Volumes, Networking, and Healthchecks
Volumes and mounts
Networking between containers
Healthchecks and restart policies
Why it matters
Docker vocabulary guide
Keep the learning going.
Installing Docker
Windows 10 installation
Mac installation
Linux installation
Container Lifecycle and Basic Commands
Common Docker commands
Why it matters
What to learn next
Continue learning about Docker

Docker is an open-source software platform that helps you simplify the process of creating, managing, running, and distributing your applications. With Docker, you can package your application along with all its dependencies into a container. Containers allow your applications to be deployed easily and uniformly. Today, we’ll dive deeper into Docker and discuss containers, modules, key terms, and more.


Get hands-on with Docker

This interactive course will help you get started with Docker containerization.

The Beginners Guide to Docker

What is Docker?#

Docker is an open-source software that runs on Linux and Windows. With Docker, you can package your application and its dependencies together into containers. Docker allows you to separate your applications from your infrastructure.

The company started as a platform as a service that was built on Linux containers. To help make and manage the containers, they built an in-house tool that they nicknamed “Docker,” which is how the technology was born. The first version was released in 2013.

Today, Docker dominates the market. Many companies use Docker to simplify the process of building, running, and managing applications. It has changed the way companies do their application development. Docker virtualizes the operating system of the computer on which it’s installed, which gives it the functionality of being extremely portable.

Docker is used in:

  • DevOps
  • Software
  • IT services
  • Staffing and recruiting
  • Finance
  • Healthcare
  • Retail
  • Etc.

Before we get into anything else, let’s talk about Docker containers.

What are containers?#

For a long time, companies have been using container technologies to address the weak points of virtual machines. We can think of containers as more lightweight versions of VMs. The important difference between containers and VMs is that containers don’t need their own operating system. All containers on a host share that host’s operating system, which frees up a lot of system resources.

What are now known as modern containers started as Linux containers (LXC). Many contributors, including Google, have helped bring container-related technologies to the Linux kernel. Without these contributions, we wouldn’t have the rich container ecosystem we have today.

Containerization wasn’t very accessible until Docker came along. Docker containers create an abstraction at the application layer. Containers package your application and its container dependencies with everything it needs to run, including:

  • the operating system
  • application code
  • runtime
  • system tools
  • system libraries
  • etc.

Docker modules#

Docker offers many different modules and plugins. Let’s take a look at some of the most popular ones.

Docker Compose#

docker-compose allows you to define and run multi-container applications. With Compose, you use a YAML file to configure your app’s services and orchestrate containers on a Docker daemon or on Docker Swarm. You can think of it as an automated multi-container workflow. Docker Compose is great for development, testing, CI workflows, and staging environments.

Docker Machine#

docker-machine allows you to deploy your containerized applications to the cloud. With Docker Machine, you can create a remote virtual machine and manage your containers. It’s a great tool for creating deployment environments and managing micro-services that run on your application. It can be used with popular cloud services such as AWS and Microsoft Azure.

Docker stack#

Docker stack allows you to manage a cluster of Docker containers with Docker Swarm. Docker stack is embedded into the Docker command-line interface (CLI). With stack, you can describe multiple services in a single file. It eliminates the need to maintain bash scripts to define services.

Docker swarm#

Docker Swarm allows you to manage multiple containers across different host machines. In other words, it’s a container orchestration tool. With Swarm, you can turn multiple Docker hosts into a single host.

Dockerfile Best Practices and Multistage Builds#

Once you’ve installed Docker and understand how containers work, the next skill is writing efficient Dockerfiles.
Poorly structured Dockerfiles lead to bulky images, long build times, and security risks — but a few best practices make a big difference.

Key tips for effective Dockerfiles#

  • Order instructions smartly
    Put layers that change less often (like installing packages) before ones that change frequently (like copying source code).
    This maximizes Docker’s layer caching and speeds up rebuilds.

  • Use multistage builds
    Build and compile in one stage, then copy only the final artifacts into a clean, minimal image.

    FROM golang:1.20 AS builder
    WORKDIR /app
    COPY go.mod ./
    COPY . ./
    RUN go build -o server .
    
    FROM alpine:latest
    WORKDIR /app
    COPY --from=builder /app/server .
    CMD ["./server"]
    

    This approach produces a small, secure runtime image containing only the binary and essential dependencies.

  • Choose smaller base images
    Favor alpine, distroless, or even scratch for reduced size and attack surface.

  • Avoid runtime bloat
    Don’t install build tools or debugging packages in the final stage — keep the runtime lean.

  • Add metadata
    Use labels for maintainers, versions, and provenance:

    LABEL maintainer="dev@company.com" version="1.0"
    
  • Minimize layers
    Combine related operations in one RUN statement:

    RUN apt-get update && apt-get install -y pkg1 pkg2 && rm -rf /var/lib/apt/lists/*
    

These best practices turn a Docker tutorial from “how to build a container” into “how to build production-grade images.”

Docker vs Kubernetes#

It’s very common to confuse Docker with Kubernetes, so let’s take some time to look at the differences between the two technologies. These technologies complement one another very well, and they are frequently used together. We’ve already explored Docker in this article, but let’s highlight some key points.

Docker

Docker is a containerization platform. We can use Docker to build and run containers. Docker Engine is a runtime environment that allows you to build and run containers on a development machine. Operating applications can be complex, especially when you have a lot of containers deployed across various servers. It can be difficult to determine the best way to coordinate and schedule multiple containers, to figure out how they communicate with one another, and to decide how to scale your containers. This is where Kubernetes comes in!

Kubernetes

Kubernetes is an open-source orchestration software for containerization platforms like Docker. It has an API that controls container operations. Kubernetes allows you to organize a cluster of VMs and schedule containers to run on those VMs. With Kubernetes, you can run Docker containers and manage your containerized applications. Your containers are grouped into pods, and you can scale and manage these pods however you want.

Wait, what’s the difference between Kubernetes and Docker Swarm?

As we discussed above, Docker Swarm allows you to manage multiple containers across different host machines.

The difference between Docker Swarm and Kubernetes is that Kubernetes is much more comprehensive than Docker Swarm. It runs across a cluster while Docker runs on one node. Kubernetes pods are divided across nodes to ensure availability.


Volumes, Networking, and Healthchecks#

Once you’re comfortable building and running containers, the next step in mastering Docker is managing data, connectivity, and container reliability.
These features make your containers production-ready and resilient.

Volumes and mounts#

To persist data across container restarts or upgrades:

  • Named volumes

    docker volume create mydata
    docker run -v mydata:/data myapp
    

    Named volumes are managed by Docker and stored under /var/lib/docker/volumes.

  • Bind mounts

    docker run -v /host/path:/container/path myapp
    

    Useful for sharing files between your host and container (e.g., development source code).

Both options help preserve state between deployments and are essential for databases, logs, and uploads.

Networking between containers#

By default, Docker containers use the bridge network for isolated communication.

  • Create a custom network

    docker network create mynet
    
  • Run containers on the same network

    docker run -d --network mynet --name web nginx
    docker run -d --network mynet --name api myapi
    

    Containers on the same network can reach each other by name-based DNS (http://api:port).

  • Expose ports to the host

    docker run -p 8080:80 myapp
    

    Maps host port 8080 to container port 80.

Tip: The old --link flag is deprecated — always use user-defined networks instead.

Healthchecks and restart policies#

Keep containers self-healing and reliable:

  • Add a healthcheck in your Dockerfile
    HEALTHCHECK CMD curl -f http://localhost:80/ || exit 1
    
  • Set restart policies
    docker run --restart unless-stopped myapp
    docker run --restart on-failure:5 myapp
    
    Docker automatically restarts failed containers according to these policies, improving uptime.

Why it matters#

Volumes keep your data safe, networks connect your services, and healthchecks ensure robustness.
Together, they turn containers into dependable, production-grade building blocks.

Docker vocabulary guide#

Let’s take a look at some common Docker terms you’ll see when working with the platform.

  • Cgroups: Control groups allow you to allocate resources among processes running on a system.

  • Container images: Docker images are files that you use to execute code in a Docker container.

  • Docker build: docker build is a command that you use to build an image from a Dockerfile.

  • Docker Engine: Docker Engine is the core product of Docker, which includes its daemon and CLI. It has an API for interacting with the Docker daemon.

  • Dockerfile: A Dockerfile is a text-based document that holds the instructions for building Docker images.

  • Docker Hub: Docker Hub is a service that allows you to find and share containers with your organization.

  • Docker Registry: Docker Registry allows you to store and distribute named Docker images. Registries are organized into repositories, and they hold all of the versions of different images.

  • Docker run: The run command allows you to create a container from a specified image and start that container using a given command.

  • Namespace: Namespaces are created when you run a container. They provide a layer of isolation, as each element of a container runs in a different namespace.

  • Pull: docker pull is a command that allows you to download a specific image or set of images.

  • Repository (repo): Docker repositories allow you to share container images with others. These images are stored as tags.

  • Tags: Docker tags are like labels that you can assign to any completed build.

  • Union filesystem (AUFS): A union filesystem layers multiple directories on a single host and presents them as a single directory.


Keep the learning going.#

Learn Docker without scrubbing through videos or documentation. Educative’s text-based courses are easy to skim and feature live coding environments, making learning quick and efficient.

The Beginners Guide to Docker


Installing Docker#

There are many different ways and places to install Docker. We’ll walk through the installation of the Docker Desktop for Windows 10, Mac, and Linux.

Docker Desktop is an application that allows you to build and share containerized applications and microservices. According to the Docker documentation, it includes:

  • Docker Engine
  • Docker CLI client
  • Docker Compose
  • Docker Content Trust
  • Kubernetes
  • Credential Helper

Windows 10 installation#

Before you can download Docker Desktop on Windows 10, you must have the following:

  • 64-bit version of Windows 10 Pro, Enterprise, or Education
  • Hardware virtualization support must be enabled in your system’s BIOS
  • The Hyper-V and Containers features must be enabled in Windows

Start with a Google search for “install Docker Desktop.” This search will take you to the download page where you can download the installer and follow the instructions.

Once it’s installed, you may have to manually start the Desktop from the Windows Start menu.

Mac installation#

As with the Windows 10 installation, the easiest way to install Docker Desktop on your Mac is to Google “install Docker Desktop.” From there, you can follow the links on the download page.

Once it’s installed, you may have to manually start the Desktop from the MacOS Launchpad.

Note: With Mac, the Docker Engine doesn’t run natively on the MacOS Darwin kernel. The Docker daemon runs inside a lightweight Linux VM that exposes the daemon and API to your Mac environment. This means that you can open a terminal on your Mac and use Docker commands.

Linux installation#

There are many ways to install Docker on Linux. You can Google search for Docker installation guides on Linux. In this section, we’ll take a look at one of the ways you can install Ubuntu Linux 20.04 LTS. We’ll assume you already have Linux installed. We’ll install Docker in two steps:

1. Update the apt package index

$ sudo apt-get update
Get:1 http://eu-west-1.ec2.archive.ubuntu.com/ubuntu.com/ubuntu focal InRelease [265
kb]
...

2. Install Docker from the official repo

$ sudo apt-get install docker.io
Reading package lists... Done
Building dependency tree
...

Container Lifecycle and Basic Commands#

Building an image is just the beginning — managing containers through their full lifecycle is core to effective Docker use.
These commands form the daily toolkit for anyone working with containers.

Common Docker commands#

  • Build an image

    docker build -t myapp:latest .
    

    Builds an image from the current directory and tags it myapp:latest.

  • List images

    docker images
    

    Shows all images available locally.

  • Run a container

    docker run -d --name myapp -p 8080:80 myapp:latest
    

    Starts a container in detached mode, mapping host port 8080 to container port 80.

  • List containers

    docker ps        # running containers
    docker ps -a     # all containers, including stopped
    
  • View logs

    docker logs myapp
    

    Displays container stdout and stderr output.

  • Access a running container

    docker exec -it myapp /bin/sh
    

    Opens an interactive shell inside the container.

  • Stop or kill a container

    docker stop myapp
    docker kill myapp
    
  • Remove a container

    docker rm myapp
    
  • Remove an image

    docker rmi myapp:latest
    

Why it matters#

Understanding the container lifecycle — from build to removal — helps you:

  • Spin up containers on demand
  • Debug live instances
  • Tear down and redeploy cleanly

Mastering these basics is essential for anyone following a Docker tutorial or managing real deployments.


What to learn next#

Congrats on taking your first steps with Docker! Docker is a popular open-source containerization platform that’s used in many different industries to simplify the process of building, securing, and managing applications. With Docker in such high demand, it’s a great tool to add to your skillset.

A great way to get practical experience with Docker is to build a project to add to your professional portfolio. Before you get started, there are still many more things to learn about Docker such as:

  • Container lifecycle
  • Docker commands
  • Creating a new container
  • Running containers

To get started learning these concepts and much more, check out Educative’s curated course The Beginners Guide to Docker. In this hands-on course, we’ll guide you through the basics of Docker to help you gain proficiency in the platform. By the end of the course, you’ll be ready to build your own Docker project to add to your portfolio!

Happy learning!

Continue learning about Docker#


Written By:
Erin Schaffer