Docker for Beginners: Why Developers Use Containers
Docker for beginners: what a container is, how it differs from a virtual machine, a first Dockerfile explained line by line, and when Docker is not worth it.
By Taiyaba · 7 min read

Docker for beginners comes down to one idea: you package your application together with everything it needs to run (the language runtime, libraries, system tools and settings) into a single unit called a container image, and that image runs the same way on your laptop, a colleague's laptop and a cloud server. Developers use containers because they remove the "it works on my machine" problem, make new team members productive in an hour instead of a day, and make deployments repeatable.
What is a container, in plain terms?
A container is a running process on a computer that has been given its own private view of the file system, network and installed software. It thinks it is alone on the machine. Inside it, your app finds exactly the PHP, Node.js or Python version it was built for, even if the host computer has something different installed.
The container starts from an image. An image is a read-only template: a stack of layers, each one adding something, such as "a slim Linux base", then "Python 3.12", then "our dependencies", then "our code". You build an image once and can start as many containers from it as you like.
Docker is the most widely used tool for building images and running containers. It is not the only one (Podman is a common alternative), but the image format is an open standard, so images built with Docker run elsewhere too.
How is a container different from a virtual machine?
People often confuse the two because both give you an isolated place to run software. The difference is what gets isolated.
| Virtual machine | Container | |
|---|---|---|
| What it includes | A full guest operating system plus your app | Only your app and its dependencies |
| Shares the host kernel? | No, it runs its own | Yes |
| Typical size | Several gigabytes | Tens to a few hundred megabytes |
| Start time | Usually tens of seconds or more | Usually a second or two |
| Isolation strength | Stronger | Good, but weaker than a VM |
Because containers share the host's kernel, you can run many more of them on one server than you could run virtual machines. The trade-off is isolation: a VM is a harder wall. For running your own code that is usually fine. For running untrusted code from strangers, it is a real consideration.
On a Mac or Windows laptop, Docker Desktop quietly runs a small Linux virtual machine and your containers live inside it. That's why Linux containers work on those machines at all.
Why developers actually use Docker
The reasons are practical, and most of them show up in the first week.
Same environment everywhere. A Laravel app built against PHP 8.3 with specific extensions will misbehave on a server running PHP 8.1. With Docker, the PHP version is written into the image, so the server can't drift from what the developer tested.
Fast onboarding. Without containers, a new developer installs a database, a cache, the right language version and a dozen tools, then spends an afternoon fixing conflicts with something already on their laptop. With a docker compose up command, the whole stack starts in a few minutes.
Clean machines. Each project's dependencies stay inside its containers. You can work on a project needing MySQL 5.7 and another needing MySQL 8 on the same laptop without either breaking.
Repeatable deployments. The image you tested is the exact image that goes to production. Nothing gets installed by hand on the server at release time. This is what makes automated pipelines trustworthy, which we cover in CI/CD explained.
Easy to scale and move. Cloud services such as AWS ECS, Google Cloud Run and Azure App Service all run container images. If you package your app as an image, moving between them is far less work than rebuilding a server.
A first Dockerfile, line by line
A Dockerfile is a text file with the instructions for building an image. Here is one for a small Node.js API:
FROM node:20-slim
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY . .
EXPOSE 3000
CMD ["node", "server.js"]
What each line does:
FROMpicks the starting image: a slim Linux with Node.js 20 already installed.WORKDIRsets the folder inside the image where the following commands run.COPY package*.jsoncopies only the dependency list first. Docker caches each step, so if your code changes but your dependencies don't, the slow install step is reused on the next build.RUN npm ciinstalls exact versions from the lock file, leaving out development tools.COPY . .adds the rest of your code.EXPOSEdocuments the port the app listens on.CMDis the command that runs when a container starts.
You build it with docker build -t my-api . and run it with docker run -p 3000:3000 my-api. The -p flag connects port 3000 on your computer to port 3000 inside the container. Add a .dockerignore file listing node_modules and .env so you don't copy local junk or secrets into the image.
A worked example: a small team running a Laravel app
Picture a three-person team in Indore maintaining a Laravel booking system for a chain of clinics. The app needs PHP 8.3, MySQL 8, Redis for queues and a worker process that sends appointment reminders.
Before Docker, one developer used XAMPP on Windows, one used Homebrew on a Mac, and the server was configured by hand two years ago. Reminders failed locally for one developer because a PHP extension was missing, and nobody could say exactly what was installed in production.
After moving to Docker, the repository holds one Dockerfile for the PHP app and a compose.yaml that defines four services: app, worker, mysql and redis. A new developer clones the repository, copies the example environment file and runs docker compose up. In about ten minutes they have the full system running with the same versions as production. The server runs the same app image, built once by the pipeline and tagged with the commit it came from. Rolling back a bad release means starting the previous tag, which takes under a minute.
The cost was roughly two days of one developer's time to write and test the files, plus some learning. For a team that onboards people or deploys weekly, that pays back quickly.
When Docker is not worth it
Docker adds a layer you have to understand, and it is easy to overdo.
- A five-page brochure site on WordPress shared hosting gains almost nothing from containers. A good managed host is simpler.
- If you are a solo developer with one project and one server that rarely changes, the main benefit is small.
- Running databases in containers in production needs care with storage volumes and backups. Many teams run the app in containers and use a managed database such as Amazon RDS instead.
- Kubernetes is a separate, much bigger step. Most small products never need it; a managed container service runs a handful of containers with far less to maintain.
- Docker Desktop is free for personal use and small businesses, but larger companies need a paid subscription under Docker's licence terms. Check the current terms if your company is above the small-business limits.
To try it yourself, the official Docker getting started guide walks you through installing Docker and running your first container.
FAQ
Is Docker hard to learn for a beginner?
The basics (build, run, stop, compose) take a day or two to get comfortable with. Production topics such as image security, networking and storage take longer, and that's where most of the real learning is.
Do I need Linux to use Docker?
No. Docker Desktop runs on Windows and macOS by starting a small Linux virtual machine in the background. On Windows it uses WSL 2, which you may need to enable first.
What is the difference between Docker and Kubernetes?
Docker builds images and runs containers on one machine. Kubernetes schedules and manages many containers across many machines, restarting them, scaling them and routing traffic. You can use Docker without Kubernetes, and most small teams should start that way.
If you would like help containerising an existing app or setting up a pipeline around it, our Cloud & DevOps team at Amionyx does this work for teams in India and abroad, and you can read more about our cloud and DevOps services in Indore.
Cover photo by James Harrison on Unsplash.
Tags
- Docker
- containers
- DevOps
- beginners
More on this topicCloud & DevOps


