When I was learning Docker, it honestly sounded confusing. Words like containers, images and virtualisation made it feel complicated. But once I used it in a real project, I realised Docker solves a very simple problem: “it works on my machine, but not on the server.”
In this guide I’ll explain Docker in plain language: what it is, how images and containers differ, how containers compare with virtual machines, and how to build and run your first container with a real example.
The Problem Docker Solves
Imagine you build a Node.js app on your laptop with Node 20 and a few libraries. You deploy it to a server running Node 16 with different system packages, and it breaks. Your teammate’s machine has yet another setup. Every environment is slightly different, and those differences cause bugs.
Docker fixes this by packaging your application together with everything it needs (runtime, libraries, configuration) into a single unit that runs the same way everywhere: your laptop, a test server, AWS or Kubernetes.
What is Docker?
Docker is a platform for building, shipping and running applications in containers. A container is an isolated process on a Linux machine that has its own file system, network and process space, but shares the host’s kernel. Because it does not need a full operating system of its own, it starts in seconds and uses far fewer resources than a virtual machine.

Image vs Container
This is the most important distinction to understand:
- Image: a read-only template containing your app and its dependencies. Think of it as a recipe or a class in programming.
- Container: a running instance of an image. Think of it as the cooked dish, or an object created from the class. You can run many containers from one image.
Images are built in layers. Each instruction in a Dockerfile adds a layer, and unchanged layers are cached, which is why rebuilding an image after a small code change is fast.
Containers vs Virtual Machines
- Virtual machines run a full guest operating system on a hypervisor. Each VM has its own kernel, takes gigabytes of disk and minutes to boot.
- Containers share the host kernel and isolate processes using Linux features called namespaces (what a process can see) and cgroups (how much CPU and memory it can use). They take megabytes and start in seconds.
Because a container is just an isolated process, if the main process inside it stops, the container stops too. That is a useful mental model when debugging.
VMs still have their place, for stronger isolation or different operating systems, and in the cloud you usually run containers on VMs such as EC2 instances.
Key Docker Terms
- Dockerfile: a text file with instructions to build an image
- Registry: a place to store and share images, such as Docker Hub or Amazon ECR
- Volume: persistent storage that survives container restarts
- Port mapping: exposing a container port on the host, e.g.
-p 8080:80
Install Docker
# Ubuntu
sudo apt update && sudo apt install -y docker.io
# Amazon Linux 2023
sudo dnf install -y docker
sudo systemctl enable --now docker
sudo usermod -aG docker $USER # log out and back in to use docker without sudo
docker --version
Your First Container
docker run -d --name web -p 8080:80 nginx
This one command pulls the official Nginx image from Docker Hub, starts a container in the background (-d), names it web, and maps port 8080 on your machine to port 80 inside the container. Open http://localhost:8080 (or your server’s IP on port 8080) and you will see the Nginx welcome page.
Useful commands to explore it:
docker ps # running containers
docker logs web # container output
docker exec -it web bash # open a shell inside the container
docker stop web && docker rm web
A Real Example: Containerising a Node.js App
Say you have a simple Express app with package.json and server.js listening on port 3000. Create a Dockerfile:
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY . .
EXPOSE 3000
USER node
CMD ["node", "server.js"]
What each line does:
FROM: start from a small official Node.js base imageWORKDIR: set the working directory inside the imageCOPY package*.jsonthenRUN npm ci: install dependencies first, so this layer is cached when only your code changesCOPY . .: add the application codeUSER node: run as a non-root user, a simple security best practiceCMD: the command the container runs
Add a .dockerignore containing node_modules and .git, then build and run:
docker build -t my-node-app:1.0 .
docker run -d -p 3000:3000 --name app my-node-app:1.0
Your app now runs identically on any machine with Docker. To deploy it to AWS, the next step is pushing the image to a registry. I show that step by step in How to Push Docker Images to AWS ECR.
Mistakes I see beginners make
- Using the
latesttag everywhere instead of versioned tags - Storing data inside the container instead of a volume, then losing it on restart
- Baking secrets or
.envfiles into images - Running containers as root when there is no need
- Using huge base images;
-alpineor-slimvariants are usually enough
Where Docker Fits in DevOps
Docker is the building block for most modern delivery pipelines: CI systems build images, registries store them, and platforms like ECS and Kubernetes run them at scale. Once you are comfortable with containers, the natural next step is Kubernetes; start with Kubernetes Pods & Containers Explained, and see the full pipeline in my end-to-end DevOps project.
Next steps with Docker
Docker is not complicated once you see it as “package the app with everything it needs, then run it anywhere.” Install it, run the Nginx example, then containerise one of your own projects; that hands-on step is where it really clicks.
I cover Docker with live demos on my YouTube channel, Madhukar Reddy (@awsandevops).

Hey thanks for these posts! keep on posting!
I pay a quick visit day-to-day some blogs and websites to read content,
except this webpage presents quality based content. Keep up the good work!
Heya! I’m at work browsing your log from my new iphone!
Just wanted to say I love reading through your blog and look forward to
all you posts! Keep up the superb work!
Have you evewr considered about adding a little bit more than just your articles?
I mean, what you say is important and everything.
But think aboiut if you added somne great photos or video clips to give your posts more, “pop”! Your content is excellent but with pics and clips, this website could definitely be one of the very best in its field.
Good blog!
You’re so awesome! I don’t tnink I’ve truly read anything like
thhis before. So nice too discover someone with some original thoughts on this subject matter.
Seriously.. thanks for starting this up. This site is one thig that’s
needed on tthe web, someone with a little originality!