Docker for Beginners — Install and Run Your First Container

Introduction

Docker is one of the most important tools in modern software development and DevOps. If you have been hearing about containers, Docker images, and Dockerfiles but are not sure what any of it means — this guide is for you.

I will explain Docker from scratch, show you how to install it, and walk you through running your very first container. No prior experience required.


What is Docker and Why Does It Matter?

Imagine you build an application on your laptop. It works perfectly. Then you hand it to a colleague and it breaks on their machine because they have a different version of Python, or a different operating system, or a missing library.

You have probably heard the phrase: “But it works on my machine!”

Docker solves this problem. With Docker, you package your application along with everything it needs — the code, runtime, libraries, and settings — into a single unit called a container. That container runs the same way on every machine, every time.


Key Docker Concepts

Container

A container is a lightweight, isolated environment that runs your application. It is similar to a virtual machine but much faster and uses far fewer resources. Multiple containers can run on the same machine without interfering with each other.

Image

A Docker image is a blueprint or template for creating containers. Think of an image as a recipe and a container as the meal made from that recipe. You can create multiple containers from the same image.

Dockerfile

A Dockerfile is a text file containing instructions to build a Docker image. It defines what goes into your container — the base OS, dependencies, your application code, and the command to run it.

Docker Hub

Docker Hub is a public registry where thousands of ready-made Docker images are stored. You can pull official images for Nginx, MySQL, Python, Node.js, and many more — without building them yourself.


How to Install Docker On Ubuntu / Amazon Linux

# Update packages
sudo apt update        # Ubuntu
sudo yum update        # Amazon Linux

# Install Docker
sudo apt install docker.io -y      # Ubuntu
sudo yum install docker -y         # Amazon Linux

# Start and enable Docker
sudo systemctl start docker
sudo systemctl enable docker

# Add your user to the docker group (so you don't need sudo every time)
sudo usermod -aG docker $USER

# Log out and log back in, then verify
docker --version

On Windows or Mac

Download and install Docker Desktop from docker.com. It includes everything you need with a simple installer.


Your First Docker Container

Let’s run your first container. This command downloads and runs the official Nginx web server:

docker run -d -p 8080:80 nginx

Breaking this down:

  • docker run — create and start a container
  • -d — run in detached mode (in the background)
  • -p 8080:80 — map port 8080 on your machine to port 80 in the container
  • nginx — the image to use (downloaded from Docker Hub automatically)

Now open your browser and go to http://localhost:8080 — you should see the Nginx welcome page!


Essential Docker Commands

# Pull an image from Docker Hub
docker pull ubuntu

# List downloaded images
docker images

# Run a container
docker run -d -p 8080:80 nginx

# List running containers
docker ps

# List all containers (including stopped ones)
docker ps -a

# Stop a container
docker stop container_id

# Remove a container
docker rm container_id

# Remove an image
docker rmi image_name

# View logs of a container
docker logs container_id

# Open a shell inside a running container
docker exec -it container_id bash

Writing Your First Dockerfile

Let’s create a simple Docker image for a Python application.

Create a file called app.py:

print("Hello from Docker!")

Create a file called Dockerfile (no extension) in the same folder:

# Start from an official Python base image
FROM python:3.11-slim

# Set the working directory inside the container
WORKDIR /app

# Copy your application file into the container
COPY app.py .

# Command to run when the container starts
CMD ["python", "app.py"]

Build the image:

docker build -t my-python-app .

Run the container:

docker run my-python-app

You should see: Hello from Docker!


Docker vs Virtual Machine

FeatureDocker ContainerVirtual Machine
Startup timeSecondsMinutes
SizeMegabytesGigabytes
PerformanceNear nativeSlower (overhead)
IsolationProcess-levelFull OS-level
PortabilityExcellentGood
Resource usageLowHigh

Why Docker is Important for DevOps and AWS

  • Consistency — Same container runs in dev, test, and production
  • Speed — Containers start in seconds, not minutes
  • Scalability — Easily run hundreds of containers with tools like Kubernetes
  • AWS Integration — AWS services like ECS, EKS, and Fargate are built around containers
  • CI/CD — Docker containers are used in almost every modern CI/CD pipeline

Conclusion

Docker has changed the way software is built and deployed. By packaging applications into containers, teams can work faster, eliminate environment issues, and deploy with confidence.

To recap what you learned:

  • A container is an isolated environment to run your application
  • An image is the blueprint for a container
  • A Dockerfile defines how to build your image
  • Docker Hub is where you find ready-made images

The next step is to practice — pull a few images from Docker Hub, run some containers, and try writing your own Dockerfile. The more you experiment, the faster you will learn.

Leave a Comment

Your email address will not be published. Required fields are marked *