syndicated · dev.to / @markyu
A practical Docker container guide focused on the commands that show image layers, process isolation, networking, volumes, and debugging.
- Published
- May 3 '24
- Reading time
- 2 min read
- Reactions
- 10
dockerdevopscontainersbeginners
The first time Docker made sense to me was not from a definition.
It was from running a container, checking the process list, deleting the container, and realizing my host system stayed clean.
Containers are not tiny virtual machines. They are isolated processes with packaged files, network settings, and resource boundaries.
Let’s prove that with commands.
Run a Container
docker run --name web-demo -d -p 8080:80 nginxOpen:
http://localhost:8080Check it:
docker psStop and remove it:
docker stop web-demo
docker rm web-demoThat is the basic lifecycle.
What Is Actually Running?
docker run --name shell-demo -it ubuntu bashInside the container:
ps aux
cat /etc/os-releaseIn another terminal on the host:
docker exec shell-demo ps auxYou are not booting a full separate machine. You are running a process in an isolated environment.
Visual map:
Host kernel
|
+-- container process: nginx
+-- container process: ubuntu bash
+-- normal host processesThat kernel sharing is why containers start fast.
Build a Small Image
Create Dockerfile:
FROM node:22-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY . .
CMD ["node", "server.js"]Build it:
docker build -t my-api:1.0 .Run it:
docker run --rm -p 3000:3000 my-api:1.0The image is the template. The container is the running instance.
Check Logs
docker logs web-demo
docker logs -f web-demoWhen a container exits immediately, logs are usually the first place I look.
Then inspect:
docker inspect web-demoinspect is noisy, but useful for environment variables, network settings, mounts, and container state.
Volumes: Data That Survives the Container
Containers are disposable. Data sometimes is not.
docker volume create mysql-data
docker run --name mysql-demo \
-e MYSQL_ROOT_PASSWORD=secret \
-v mysql-data:/var/lib/mysql \
-d mysql:8Remove the container:
docker rm -f mysql-demoThe named volume can still exist:
docker volume lsThat separation matters in production.
Networking: Host Port vs Container Port
This command:
docker run -p 8080:80 nginxmeans:
host port 8080 ---> container port 80The left side is your machine. The right side is inside the container.
I still see beginners flip those numbers and then wonder why the app is unreachable.
Containers vs Virtual Machines
| Topic | Container | VM |
|---|---|---|
| Startup | seconds | slower |
| Kernel | shares host kernel | own guest OS |
| Isolation | process-level | machine-level |
| Image size | usually smaller | usually larger |
| Best fit | app packaging | strong OS isolation |
I would not say containers are "better" than VMs. They solve different problems.
My Docker Debug Checklist
docker ps -a
docker logs <container>
docker inspect <container>
docker exec -it <container> sh
docker images
docker volume ls
docker network lsIf you know those commands, you can debug most beginner Docker problems.
Final Thought
Docker becomes less mysterious when you stop treating it as magic packaging and start inspecting what it actually runs.
What Docker command helped containers finally click for you?
Related reading
Network Address Calculation: The Subnet Math That Matters
A practical subnetting guide showing how to calculate a network address from an IP address and mask using binary math and simple examples.
networking
Kubernetes Is Useful, but Only After These Basics Hurt
A practical Kubernetes guide for developers: pods, deployments, services, config, scaling, and when not to introduce Kubernetes too early.
kubernetes
Frontend Linear Data Structures Deep Dive: Arrays, Stacks, Queues, and Linked Lists
The Big Picture Before diving into stacks, queues, and linked lists, it helps to know...
computerscience
originally published
This post first ran on dev.to. Comments and reactions live there.
Continue on dev.to