This Docker for developers guide takes you from zero to a working daily workflow with containers. Docker packages your application, with its libraries and dependencies, into a container that runs the same way everywhere. The short answer is that you need three things to get started: Docker installed, a Dockerfile that describes how to build your application image, and a habit of running your code in containers from day one.
Docker was first released publicly in 2013, and it became the standard way developers package applications because it solves the old problem of code that works on one machine and fails on another. A container shares the host operating system’s kernel, so it starts in seconds and uses far less memory than a virtual machine. If you want the wider context first, our guide to cloud native computing explained describes how containers fit into modern systems.
Key takeaways
- Docker for developers starts with three pieces: the Engine that runs containers, a Dockerfile that builds images, and Compose for multi-container applications.
- An image is a layered, read-only template; a container is a running instance of that image, and the two should never be confused.
- Write Dockerfiles with small base images, cached layers and a non-root user, and keep secrets out of the image entirely.
- Docker Compose runs a whole application stack, such as a web server and a database, with a single command.
- Volumes hold data that must survive a container, and named volumes are the reliable way to store database data locally.
Install Docker the right way
Start with the installation that matches your machine. On Linux, install Docker Engine from Docker’s official repository, which gives you the open-source daemon and command-line tools free under the Apache 2.0 licence. On Mac and Windows, install Docker Desktop, which bundles the Engine in a virtual machine with a graphical interface and Compose.
Check the licensing before installing Desktop at work. Docker Desktop is free for personal use, education, non-commercial open source and businesses with fewer than 250 employees and under 10 million dollars in annual revenue, and larger organisations need a paid subscription. Docker Engine on Linux has no such restriction, which is why most servers install the Engine directly. Verify the install by running the hello-world image. Best for: new developers who want a confirmed working setup before writing any of their own code.
| Option | What you get | Licence | Best for |
|---|---|---|---|
| Docker Engine on Linux | Daemon, command line, Compose, Buildx | Free, Apache 2.0 | Servers, CI runners, Linux workstations |
| Docker Desktop on Mac | Engine in a virtual machine, plus GUI and extras | Free below the size limits, paid above them | Mac laptops and development teams |
| Docker Desktop on Windows | Engine in a virtual machine, plus GUI and extras | Free below the size limits, paid above them | Windows laptops and development teams |
Your first container
The fastest way to understand containers is to run one. The command docker run hello-world pulls the image if it is not already local, creates a container from it, runs it and exits. A web server image is more instructive: running it with a port mapping lets you open the application in your browser.
Three commands cover most daily container work. The docker ps command lists running containers, docker logs shows what a container has printed, and docker exec opens a shell inside a running container. The docker stop and docker rm commands shut a container down and remove it, while the image stays available for the next run. Containers are disposable by design: the image can recreate one in seconds. Best for: learning the container lifecycle hands-on before you build anything of your own.
Writing your first Dockerfile
A Dockerfile is a short text file listing the steps to assemble an image. Each instruction creates a layer, and Docker caches layers so that rebuilding after a small code change reuses everything that did not change. A typical Dockerfile starts from a language runtime image, copies the dependency files, installs the dependencies, copies the application code, and sets the command that starts the server.
Order matters more than most beginners expect. Copy the dependency list and install dependencies before copying the application code, because the dependency layer then stays cached while you change code freely. Copying all the code first means every small edit reinstalls every dependency.
FROM node:22-alpine
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci --omit=dev
COPY . .
USER node
EXPOSE 3000
CMD ["node", "server.js"]
The example above shows the pattern for a Node.js application. It uses a small Alpine-based image, installs only production dependencies, and runs as the non-root node user. Use a .dockerignore file to keep local clutter, such as node_modules and git history, out of the build context. Best for: any application you intend to run in more than one place, because the Dockerfile becomes its portable build recipe.
Images, containers and registries
The three concepts are easy to confuse, so keep them distinct. An image is a read-only template built from a Dockerfile, stored as a stack of layers. A container is a running instance of an image, with a thin writable layer on top for anything it changes while it runs. A registry is a service that stores images so they can be shared, with Docker Hub as the default registry.
Tag images deliberately. The latest tag moves every time you push, which makes it useless for knowing which version is actually running. Tag images with a version number or a commit identifier, and use that exact tag when you deploy. Images are layered, and layers are shared: if ten images start from the same base image, that base is downloaded once. For the bigger picture of how images move from build to cluster, see our guide to GitOps explained. Best for: teams that need reproducible deployments, where the same image runs in development, testing and production.

Docker Compose: running the whole stack
Real applications rarely run alone. A web application usually needs a database, and often a cache as well. Docker Compose defines all of these in a single YAML file, so the stack starts with one command and stops with another. Each service in the file becomes one or more containers, connected on a shared network.
Compose files are also where development configuration lives. You can mount your source code into the web container so edits appear immediately and give each service the environment variables it needs. Keep production and development Compose files separate: a development file mounts code and opens extra ports, while a production setup should use prebuilt images and named volumes. Compose is a development tool, not an orchestrator, and when one machine stops being enough, that is the moment to look at Kubernetes, as our Kubernetes tutorial explains. Best for: local development stacks and small deployments where the whole application fits on one machine.
Volumes and data that must survive
By default, anything a container writes disappears when the container is removed. That is fine for logs and temporary files, but it is a disaster for a database. Volumes store data outside the container, in a location Docker manages, so it survives restarts, rebuilds and removals.
Use named volumes for databases and other persistent data. A named volume is created once, referenced by name in the Compose file, and reused by every container that mounts it. Bind mounts, which map a host directory into a container, are better suited to development, where you want to edit code on the host and see it inside the container. Back up volumes like any other data store: a named volume is not a backup, and deleting it removes the data it holds. Best for: databases, uploaded files and any state that must outlive a single container.
Dockerfile best practices
Small habits in a Dockerfile compound into faster builds and safer images. Start from the smallest base image that fits, such as a slim or Alpine variant of your runtime, and pin it to a specific version. Install only the dependencies the application needs, and clean up package manager caches in the same layer that created them.
Run as a non-root user. Containers run as root by default, which means a vulnerability in the application can give an attacker root inside the container. Creating a dedicated user, or using the one many official images already provide, removes a whole class of risk. Never copy secrets, such as API keys or passwords, into an image, because anyone with the image can read them; pass secrets at run time through environment variables instead. Finally, keep the image to one purpose: one process per container is what makes containers composable and replaceable. Best for: every project, because these habits cost minutes to adopt and pay off on every build afterwards.
Debugging containers that misbehave
When a container fails, start with its logs. The docker logs command shows the application’s output, and most startup failures announce themselves there, whether a missing environment variable or a database connection that was refused. Add the follow flag to watch logs live.
If the logs do not explain it, open a shell inside the container with docker exec and look around: check that the files are where the application expects them and that the container can reach its database. The docker inspect command shows the container’s configuration, which is where configuration mistakes usually hide. The most common beginner failures have a short list of causes: a container that exits immediately usually has a bad start command, one that runs but is unreachable usually has a port mapping problem, and a database that loses data on restart usually has no volume. Best for: developers who would rather fix a container in minutes than rebuild it blindly and hope.
Daily workflow checklist
- Start the stack with Compose each morning and confirm every service is healthy.
- Rebuild the image after changing dependencies, and use the cached build for code-only changes.
- Run the test suite inside containers, against the same database version production uses.
- Tag every image you push with a version or commit identifier, never with latest alone.
- Check image size after adding a dependency, and remove anything the application does not need.
- Prune stopped containers and unused images weekly so the local disk does not fill up.
- Keep secrets in environment variables or a secrets manager, never in a Dockerfile or an image layer.
Frequently asked questions
Do I need Docker Desktop or Docker Engine?
On Linux, install Docker Engine directly, which is free and open source. On Mac or Windows, install Docker Desktop, which bundles the Engine in a virtual machine. Desktop is free for personal use, education and small businesses, while larger organisations need a paid subscription.
What is the difference between an image and a container?
An image is a read-only template built from a Dockerfile, made of stacked layers. A container is a running instance of an image, with a thin writable layer on top. You can run many containers from one image, and removing a container does not remove its image.
How do I keep database data when a container restarts?
Use a named volume. Mount the volume at the database’s data directory, and Docker stores the data outside the container, so it survives restarts, rebuilds and removals. A container without a volume loses everything it wrote when it is removed.
What is Docker Compose used for?
Docker Compose defines a multi-container application in one YAML file, such as a web server, a database and a cache, and starts the whole stack with a single command. It is aimed at local development and small deployments on one machine.
Should I learn Docker before Kubernetes?
Yes. Containers are the foundation that Kubernetes assumes you already understand. Learn to build images, run containers and use Compose first, and the concepts of pods, Deployments and Services will make far more sense.







