Docker Tutorial for Beginners: Basics, Architecture, Containers

โšก Smart Summary

Docker is a containerization platform that packages applications and their dependencies into portable, lightweight containers. This overview explains Docker architecture, installation on Ubuntu, essential commands, and how containers differ from traditional virtual machines for faster software delivery.

  • ๐Ÿณ Containerization: Docker virtualizes at the operating-system level, so containers share the host kernel and use fewer resources than virtual machines.
  • ๐Ÿงฑ Architecture: The Docker engine (dockerd), images, registries, and containers form the client-server architecture behind every Docker workflow.
  • ๐Ÿ“ฆ Images and Containers: An image is a read-only template, while a container is a running copy, and one image can start many containers.
  • ๐Ÿ—„๏ธ Registries: Docker Hub stores public and private images, giving you millions of ready-to-use images to pull and run.
  • โš™๏ธ Installation: On Ubuntu you add the Docker APT repository and GPG key, then install the docker-ce package with apt-get.
  • โŒจ๏ธ Core Commands: Manage containers with docker pull, run, start, stop, ps, stats, and images from the command line.

Docker tutorial for beginners covering architecture, installation on Ubuntu, and basic container commands

Docker is one of the most popular containerization platforms used in modern DevOps and cloud workflows. This Docker tutorial for beginners explains what Docker is, how the Docker architecture works, how to install Docker on Ubuntu, and the basic commands used to manage images and containers.

What is Docker?

Docker is a software development platform for virtualization that lets multiple operating systems run on the same host. It helps you separate infrastructure from applications so you can deliver software quickly. Unlike hypervisors, which are used to create virtual machines (VMs), Docker performs virtualization at the system level using units called Docker containers.

Docker containers run on top of the host operating system, as shown in the image below. This improves both efficiency and security. You can also run more containers than virtual machines on the same infrastructure, because containers use fewer resources.

Virtualization in Docker vs Hypervisor
Virtualization in Docker vs Hypervisor

Unlike VMs, which can communicate directly with the host hardware (for example, an Ethernet adapter that creates more virtual adapters), Docker containers run in an isolated environment on top of the host OS. Even if your host runs Windows, you can run Linux images inside containers with the help of Hyper-V, which automatically creates a small VM to virtualize the base image.

Now that you know what Docker is, let us look at the main reasons teams choose it.

Why use Docker?

Here are the key reasons to use Docker:

  • Docker is software used for virtualization, allowing multiple operating systems to run on the same host.
  • Docker is a client-server application, which means clients communicate with a server.
  • Docker images act as the “source code” for containers; you use them to build.
  • Docker supports two types of registries: public and private.
  • Containers are the organizational units of Docker. In simple terms, an image is a template and a container is a copy of that template, so you can run multiple containers from the same image.

These benefits come from the way Docker is designed. The following section breaks down the Docker architecture and its core components.

Docker Architecture

Now, in this Docker container tutorial, let us look at the main components of the Docker architecture.

Docker Architecture components: engine, images, registries, and containers

Docker Architecture

Docker Engine

Docker is a client-server application, which means we have clients that relay requests to a server. The Docker daemon, called dockerd, is the Docker engine that represents the server. The daemon and the clients can run on the same or a remote host, and they communicate through a command-line client binary and a full RESTful API that interacts with dockerd.

Docker Images

Docker images are the “source code” for our containers; we use them to build containers. Images can have software pre-installed, which speeds up deployment. They are portable, and you can use existing images or build your own.

Docker Registries

Docker stores the images we build in registries. There are public and private registries. Docker has a public registry called Docker Hub, where you can also store images privately. Docker Hub has millions of images that you can start using right away.

Docker Containers

Containers are the organizational units of Docker and one of its basic concepts. When we build an image and run it, we are running it inside a container. The container analogy is used because of the portability of the software running inside it: you can move, “ship”, modify, manage, create, or destroy it, just as cargo ships handle real containers.

In simple terms, an image is a template, and a container is a copy of that template. You can have multiple containers (copies) of the same image.

The interaction between these different components shows how Docker container technology works together. Commands such as docker pull and docker run, which we cover later, let you manage this workflow.

With the architecture in mind, let us install Docker so you can try these components yourself.

How to install Docker on Linux/Ubuntu

Below is a step-by-step Docker installation process on Linux/Ubuntu:

Step 1) To install Docker, you need the Docker team’s DEB packages. First, some prerequisite Ubuntu packages are required. Use the command below to install them.

$ sudo apt-get install \
apt-transport-https \
ca-certificates curl \
software-properties-common

*the sign โ€œ\โ€ is not necessary itโ€™s used for the new line, if want you can write the command without using โ€œ\โ€ in one line only.

Step 2) Add the official Docker GPG key with the fingerprint. Use the below Docker command to enter the GPG key.

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Step 3) Next, add the Docker APT repository using the command below.

$ sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"

You may be prompted to confirm that you wish to add the repository and have the GPG key automatically added to your host. The lsb_release command should populate the Ubuntu distribution version of your host.

Step 4) After adding the GPG key, update the APT sources using the below Docker command.

$ sudo apt-get update

You can now install the Docker package itself.

Step 5) Once the APT sources are updated, start installing the Docker packages on Ubuntu using the below Docker command.

$ sudo apt-get install docker-ce

The command above installs Docker and other required packages. Before Docker 1.8.0, the package name was lxc-docker, and between Docker 1.8 and 1.13, the package name was docker-engine.

NOTE: Docker for Windows requires Windows 10 Pro or Enterprise version 14393, or Windows Server 2016 RTM, to run.

How to use Docker using basic Docker Commands

Here is how to use Docker with a few basic Docker commands.

The most basic command you should run after installing Docker is docker info, as mentioned earlier.

$ sudo docker info

You should get a result similar to the following.

Use Docker using basic Docker commands, showing docker info output

As shown in the Docker example above, we can see information about Docker containers: how many are running, paused, or stopped, and how many images have been downloaded. Now let us get our first image.

$ sudo docker pull alpine

With this command, we are telling Docker to download the image alpine, pulling it from the public registry in the latest version, which is set by default.

*alpine is a minimal Docker image based on Alpine Linux with a complete package index and only 5 MB in size.

If we want to run the image as a container, we use the following command.

$ sudo docker run -i -t alpine /bin/bash

Running the command sends us directly to the alpine terminal. The -i flag keeps STDIN open from the container even when you are not attached to it; this persistent standard input is one half of what you need for an interactive shell. The -t flag is the other half and instructs Docker to assign a pseudo-tty to the container. Together they give us an interactive shell in the new container. We exit the container with a simple exit command.

Now, in this Docker basics tutorial, we can try running an Ubuntu image.

$ sudo docker run -it ubuntu /bin/bash

Notice that Docker checks for the image locally, and if it is not there, the image is pulled from the image library automatically. Once again, we have an interactive shell running. We can also name containers as we run them.

$ sudo docker run โ€“-name our_container -it ubuntu /bin/bash

Then we exit again. We can also run a container we previously created without an interactive shell.

$ sudo docker start container_name

And we stop the container by writing docker stop container_name.

$ sudo docker stop container_name

If we want to see all running containers, we simply run the following.

$ docker ps

For all containers, we add “-a” at the end of the same command, like docker ps -a. This command shows the container ID, which image it uses, when it was created, its running status, exposed ports, and a randomly generated name for easier management.

When we run containers, we often want to know how many resources they are using. For that purpose, we can use the following command.

$ docker stats

You can also see which images you have downloaded locally, along with information about them.

$ sudo docker images

The command in the Docker example above displays each Docker image with a tag showing the image version, a distinctive image ID, the creation date, and the image size.

To understand why containers are such an improvement, it helps to look at how virtualization evolved.

What is Virtualization?

Earlier, deploying a service was slow and painful. Developers would write code, and then the operations team would deploy it on bare-metal machines, where they had to watch out for library versions, patches, and language compilers so the code would work. If there were bugs or errors, the process would start all over again: the developers would fix the issue, and the operations team would redeploy.

Things improved with the creation of hypervisors. Hypervisors run multiple virtual machines, or VMs, on the same host, which may be running or turned off. VMs greatly reduced the waiting time for deploying code and fixing bugs, but the real game changer was Docker containers.

Docker’s popularity is also driven by orchestration tools that manage containers at scale, such as Kubernetes. Before moving on, here is a quick reference of the most important Docker commands.

Important Docker Commands

Below are the important Docker commands:

Command Description
docker info Information Command
docker pull Download an image
docker run -i -t image_name /bin/bash Run image as a container
docker start our_container Start container
docker stop container_name Stop container
docker ps List of all running containers
docker stats Container information
docker images List of images downloaded
Docker Cleanup Kill all running containers.

Also, read these Docker job interview questions and answers for freshers as well as experienced professionals.

FAQs

A Docker container shares the host operating system kernel and isolates only the application, so it is lightweight and starts in seconds. A virtual machine bundles a full guest operating system, which makes it larger, slower to boot, and more resource-intensive.

A Dockerfile is a plain-text script containing instructions such as FROM, RUN, COPY, and CMD. Docker reads these instructions to build an image automatically. Each line adds a layer, letting you reproduce the same environment on any machine.

Docker Compose defines and runs multi-container applications using a single YAML file. You describe each service, network, and volume once, then start everything with the docker compose up command. It is ideal for local development and testing of connected services.

Docker builds and runs individual containers, while Kubernetes orchestrates many containers across a cluster. Kubernetes adds automatic scaling, self-healing, and load balancing. In practice, Docker packages the application and Kubernetes manages it in production.

Docker Engine is free and open source under the Apache 2.0 license. Docker Desktop is free for personal use, education, and small businesses, but larger companies need a paid subscription. Docker Hub offers both free and paid image-hosting plans.

Docker runs natively on Linux and is supported on Windows and macOS through Docker Desktop. On Windows and Mac, Docker uses a lightweight virtual machine to run the Linux kernel that containers require. Most container images are Linux-based.

AI assistants generate Dockerfiles, docker-compose files, and CLI commands from plain-language prompts. They also read build logs and container errors, explain the cause, and suggest fixes. Always review generated configuration for correct image tags, paths, and security before running it.

Yes. GitHub Copilot and ChatGPT can draft Dockerfiles and Compose files from a short comment or description. They speed up boilerplate, but you should verify base images, versions, and best practices, because generated snippets may use outdated defaults.

Summarize this post with: