Skip to main content

Getting started with Docker: containerize your first app

· 2 min read
Haythem Rehouma
Founder & Lead DevOps @ InSkillOps

Docker is often the first building block you meet in DevOps. It packages an application with all its dependencies into a portable unit: the container. In this article, we start from scratch and run our first containerized app.

Image vs container

Two concepts you shouldn't confuse:

  • Image: an immutable template containing your application and its environment.
  • Container: a running instance of an image.

You build an image once, then start as many containers as needed from it.

A first Dockerfile

Let's take a small Node.js app. At the project root, create a Dockerfile:

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

A few good practices already present here:

  • a lightweight base image (alpine);
  • copy package*.json first to leverage layer caching on later builds;
  • install production dependencies only.

Build and run

# Build the image
docker build -t my-app:1.0 .

# Run a container
docker run -d -p 3000:3000 --name my-app my-app:1.0

Your app is now available at http://localhost:3000. To inspect what's running:

docker ps           # active containers
docker logs my-app # application logs

What's next?

Once you've got this foundation, the natural next steps are:

  1. Docker Compose to orchestrate multiple services (app + database);
  2. moving to Kubernetes when you need to scale;
  3. integrating into a CI/CD pipeline to build and publish images automatically.

We cover each of these in depth in the InSkillOps courses. Happy building!