Getting Started with Docker: A Guide for Absolute Beginners

Arief ShaikArief Shaik
9 min read

What is Docker?

Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications. By taking advantage of Docker's methodologies for shipping, testing, and deploying code, you can significantly reduce the delay between writing code and running it in production.

Before Docker :

Before Docker, deploying software was often a nightmare. Developers would face issues like:

  • Dependency conflicts

  • Environment mismatches ("It works on my machine")

  • Heavyweight virtual machines

Virtual machines helped to an extent, but they came with their own challenges — high resource usage and slower boot times.

Containers versus virtual machines (VMs):

Without getting too deep, a VM is an entire operating system with its own kernel, hardware drivers, programs, and applications. Spinning up a VM only to isolate a single application is a lot of overhead.

container-vm-whatcontainer_2

A container is simply an isolated process with all of the files it needs to run. If you run multiple containers, they all share the same kernel, allowing you to run more applications on less infrastructure.

What is a Container? | Docker


Installing Docker:

Docker can be installed on all major operating systems.

https://www.docker.com/

you can go to the above link and download docker according to your operating system.


Docker architecture

What is Docker? | Docker Docs

Docker uses a client-server architecture. The Docker client talks to the Docker daemon, which does the heavy lifting of building, running, and distributing your Docker containers. The Docker client and daemon can run on the same system, or you can connect a Docker client to a remote Docker daemon. The Docker client and daemon communicate using a REST API, over UNIX sockets or a network interface. Another Docker client is Docker Compose, that lets you work with applications consisting of a set of containers.

The Docker daemon

The Docker daemon (dockerd) listens for Docker API requests and manages Docker objects such as images, containers, networks, and volumes. A daemon can also communicate with other daemons to manage Docker services.

The Docker client

The Docker client (docker) is the primary way that many Docker users interact with Docker. When you use commands such as docker run, the client sends these commands to dockerd, which carries them out. The docker command uses the Docker API. The Docker client can communicate with more than one daemon.

Docker Desktop

Docker Desktop is an easy-to-install application for your Mac, Windows or Linux environment that enables you to build and share containerized applications and microservices.

Docker registries

A Docker registry stores Docker images. Docker Hub is a public registry that anyone can use, and Docker looks for images on Docker Hub by default. You can even run your own private registry.


Core Docker Concepts:

Images

Images are read-only templates used to create Docker containers. They contain the application code, runtime, libraries, and all necessary dependencies. Think of them like a recipe that defines how your app should run.

Containers

A container is a running instance of an image, executing the application in an isolated environment. It includes everything needed to run the app and can be started, stopped, or deleted independently. Think of it as the meal created from a recipe.

Dockerfile

A Dockerfile is a text-based script containing instructions to build a Docker image. It defines the base image, working directory, files to copy, commands to run, and how the application should start. It automates the entire image creation process.

Docker Hub

Docker Hub is a cloud-based registry where Docker users can find and share container images. It hosts official images (like node, nginx, python) and lets developers push and pull custom images. It's like GitHub, but for Docker images.

Volumes

Volumes are used to store data persistently outside of the container's filesystem. Even if the container is deleted, the data inside a volume remains intact. This is essential for databases or apps needing long-term storage.

Networks

Docker networks enable communication between containers, allowing them to work together as a system. They provide isolated environments with customizable connectivity and security. Useful in multi-container apps like web + database stacks.


Basic Structure of a Dockerfile

A Dockerfile is made up of a sequence of instructions that tell Docker how to construct an image. Here's the typical structure, in order of appearance:

1. FROM – Base Image

FROM python:3.9
  • This specifies the base image your image is built on.

  • It’s like saying “start from a ready-made setup that already has Python 3.9 installed.”

  • Common base images: ubuntu, alpine, node, python, nginx

2. WORKDIR – Working Directory

 WORKDIR /app
  • Sets the working directory inside the container.

  • All subsequent commands like COPY, RUN, CMD, etc., will be run from this directory.

3. COPY – Copy Files

 COPY . /app
  • Copies files from your local directory (.) into the container’s file system.

  • In this case, it places everything in the /app directory inside the container.

4. RUN – Execute Commands

 RUN pip install -r requirements.txt
  • Executes commands during the image build process.

  • Commonly used to install dependencies, compile code, or update packages.

  • Each RUN creates a new layer in the image.

5. CMD – Default Command to Run

 CMD ["python", "app.py"]
  • Specifies the default command the container should run when started.

  • Only one CMD is allowed; if multiple are specified, only the last one is used.

  • Use exec form (["executable", "arg1", "arg2"]) for best practices.

  • ENTRYPOINT – Like CMD, but used when you want the container to always run a specific command. Often used with CMD to allow argument overrides.

Execution Flow

  1. Docker reads the Dockerfile from top to bottom.

  2. Each instruction creates a layer (cached for faster rebuilds).

  3. At the end, you get a Docker image you can run as a container.

FROM python:3.9
WORKDIR /app
COPY . /app
RUN pip install -r requirements.txt
EXPOSE 5000
CMD ["python", "app.py"]

Build the Image

Open a terminal in the directory containing your Dockerfile and run:

 docker build -t my-python-app .
  • -t my-python-app gives your image a name (my-python-app)

  • . tells Docker to use the current directory (where the Dockerfile is) as the build context

To confirm it’s built:

 docker images

You’ll see your image listed like this:

        TAG       IMAGE ID       CREATED         SIZE
my-python-app     latest    abc123def456   10 seconds ago  125MB

How to Run a Docker Container

Once the image is built, run it using:

 docker run my-python-app

If your app runs a service (like a web app), you’ll likely need to map ports:

 docker run -p 5000:5000 my-python-app
  • -p 5000:5000 maps host port 5000 to container port 5000

This builds an image for a Python app with dependencies and exposes port 5000.

Useful Docker Commands

CommandDescription
docker psLists running containers
docker ps -aLists all containers (including stopped)
docker stop <container_id>Stops a running container
docker rm <container_id>Deletes a stopped container
docker rmi <image_id>Deletes an image
docker exec -it <container_id> bashOpens an interactive shell in the container
docker logs <container_id>Shows logs from a container

Run in Detached Mode (in Background)

docker run -d -p 5000:5000 my-python-app
  • -d means detached — the container runs in the background

Docker Volumes: Persistent Storage

What is a Volume?

A volume is Docker’s way of persisting data outside of a container’s lifecycle. This means your data won’t be lost when the container stops or is deleted.

How to Create a Volume

docker volume create mydata
  • This creates a volume named mydata.

List Volumes

docker volume ls

Remove a Volume

docker volume rm mydata

Use a Volume in a Container

docker run -d \
  -v mydata:/app/data \
  --name volume-demo \
  my-python-app
  • -v mydata:/app/data: Mounts the volume inside the container at /app/data

  • Data written to /app/data will be saved in the mydata volume, even if the container is removed

View Volume Mounts in a Running Container

docker inspect volume-demo

Useful Docker Commands

FeatureCommandDescription
Createdocker volume create myvolCreates a new named volume myvol
Listdocker volume lsLists all volumes
Inspectdocker volume inspect myvolShows detailed info about a volume
Use in run-v myvol:/path/in/containerMounts a volume inside a container
Anonymous-v /path/in/containerCreates and mounts an unnamed volume
Removedocker volume rm myvolDeletes a specific volume
Prunedocker volume pruneDeletes all unused volumes

Docker Networks: Container Communication

What is a Network?

Docker networks allow containers to communicate with each other securely and flexibly — especially useful in multi-container setups like microservices.

Create a Docker Network

docker network create mynetwork
  • This creates a user-defined bridge network named mynetwork

List Networks

docker network ls

Remove a Network

docker network rm mynetwork

Connect Containers to a Network

docker run -d --name app1 --network mynetwork my-python-app
docker run -d --name app2 --network mynetwork my-other-app
  • Both app1 and app2 can now talk to each other by container name (e.g., http://app2 from app1)

Connect an Existing Container to a Network

docker network connect mynetwork volume-demo

Inspect a Network

docker network inspect mynetwork

Example: Volume + Network + Run

docker volume create myvolume
docker network create mynetwork

docker run -d \
  -v myvolume:/app/data \
  --network mynetwork \
  --name mycontainer \
  my-python-app

Useful Docker Commands

FeatureCommandDescription
Createdocker network create mynetCreates a new custom bridge network
Listdocker network lsLists all Docker networks
Inspectdocker network inspect mynetDisplays detailed info about the network
Use in run--network mynetConnects a container to a specific network
Connectdocker network connect mynet containerConnects a running container to a network
Disconnectdocker network disconnect mynet containerDisconnects a container from a network
Removedocker network rm mynetDeletes a specific network
Prunedocker network pruneDeletes all unused networks

Resources

0
Subscribe to my newsletter

Read articles from Arief Shaik directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Arief Shaik
Arief Shaik

I’m a passionate DevOps and cloud enthusiast with hands-on experience in building and automating modern infrastructure using tools like Docker, Terraform, Jenkins, and GitHub Actions. My core skill set includes Java, Python, shell scripting, and deploying containerized applications on Azure and AWS. I actively work on real-world projects involving CI/CD, infrastructure as code, cloud deployment, and Linux automation. Driven by curiosity and consistency, I enjoy turning complex problems into simple, automated solutions. I’m always exploring new technologies and looking to contribute to open-source projects and collaborate with the developer community.