DevOps

Docker Application Containerization: A Beginner's Guide

ahmet
4 min read
#Docker#DevOps#Container
Docker Application Containerization: A Beginner's Guide
Learn the basics of containerizing your apps with Docker, your first Dockerfile, and the practical commands you need, step by step.

Your app runs fine on your machine but refuses to start on the server. If that sounds familiar, you are not alone. Docker exists to solve exactly this "but it worked on my machine" problem, and this guide is for anyone starting from the ground up.Containerization means putting everything your application needs to run into a single package. The code, the libraries, the runtime; all of it lives inside. Wherever you move that package, it behaves the same way. The differences between your dev machine, your test server, and production stop bothering you.

What exactly is Docker?

Docker is a platform that packages and runs applications inside isolated units called containers. Each container comes with its own filesystem, network interface, and processes. Unlike virtual machines, though, it shares the operating system kernel with the host. That makes it much lighter and lets it start in seconds.A virtual machine carries a whole operating system, while a container carries only your app and its dependencies. You can comfortably run dozens of containers on a single server. The official getting started guide walks through this logic with hands-on examples.

Image versus container

These are the two concepts beginners mix up the most. The relationship between them is actually simple. An image is a template, and a container is the live copy produced from that template.


ConceptWhat it doesState
Image | A read-only template holding all of the app's files and dependencies | Sits on disk
Container | A live instance produced from an image, running with its own process | Running

You can produce as many containers as you want from one image. Think of a blueprint in architecture; you build many houses from the same plan. You define the image once, then run it again and again.

Building an image with a Dockerfile

The path to producing an image runs through a text file called a Dockerfile. This file holds the steps that describe how the image gets built. Which base image to use, which files to copy, and how the application starts are all defined here.For a simple Node.js app, a Dockerfile might look like this:

FROM node:20-alpine
WORKDIR /app
COPY package.json .
RUN npm install
COPY . .
EXPOSE 3000
CMD ["node", "server.js"]

Each line adds a new layer to the image. Docker caches these layers, so later builds finish much faster. Copying dependencies before your code matters because of this caching behavior.

Your first practical steps

Once Docker is installed, the commands you need are few. The sequence below covers the whole flow, from packaging an application to running it.

  1. Place a Dockerfile in your project's root directory.
  2. Build the image: docker build -t myapp .
  3. Start the container: docker run -p 3000:3000 myapp
  4. See running containers: docker ps

Do not forget to add a .dockerignore file too. It leaves out things like node_modules, .git, and .env. Your image shrinks, and your secrets do not leak into the image by accident.

Managing more than one service

Real applications rarely end with a single container. You will have a database, a cache layer, and an app server. This is where Docker Compose steps in. You define every service in one YAML file and bring them all up with a single command.In the Compose file you describe each service separately, and Docker wires up the network between them automatically. The version field from older releases is no longer needed; you can start straight with the services block. Add health checks and Docker can spot a broken service and restart it.

Heading to production

The real power of containers shows up when you run them on a server. Thanks to their lightweight design, they scale comfortably on a VPS with NVMe disks and guaranteed CPU and RAM. When traffic grows, adding new container instances takes minutes.At Kritm Cloud Solutions, our Turkey-based cloud infrastructure is built for these workloads. With hourly billing and server creation in minutes, you can ship your Docker projects fast. Take a look at our cloud solutions, or get in touch for a setup that fits your needs.In short, Docker makes your applications independent of their environment. Once you grasp the image and container distinction, writing your first Dockerfile takes less than half an hour. Start with a small project, practice the commands, then move to multi-service setups with Compose.