We use cookies to understand how the site is used and to display ads. Analytics and advertising only run after you accept. You can change your choice anytime. Privacy policy

Skip to content
devvkit
$devvkit learn --librarie docker-guide

Docker Guide

[containers][devops][deployment][cli]
Universal
Install
# macOS / Windows
# Download from https://docker.com/products/docker-desktop

# Linux
curl -fsSL https://get.docker.com | sh

Docker changed how we ship software. Instead of "it works on my machine," you get a reproducible environment defined in a Dockerfile.

A container shares the host kernel, starting in milliseconds and using far fewer resources than a VM.

Images

Pull an image· Download a pre-built image.
docker pull node:20-slim
List images· Show downloaded images.
docker images
Build an image· Build from a Dockerfile.
docker build -t my-app:latest .
Remove an image· Delete an image.
docker rmi node:20-slim

Containers

Run a container· Start a container from an image.
docker run -d -p 3000:3000 --name my-app my-app:latest
Run interactively· Start with a shell for debugging.
docker run -it node:20-slim /bin/bash
List containers· Show running containers.
docker ps
Stop a container· Gracefully stop.
docker stop my-app
View logs· Follow logs from a container.
docker logs -f my-app
Exec in container· Run command in running container.
docker exec -it my-app /bin/bash

Dockerfile

Dockerfile· Multi-stage build for Node.js.
FROM node:20-slim AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

FROM node:20-slim
WORKDIR /app
COPY --from=builder /app/dist ./dist
EXPOSE 3000
CMD ["node", "dist/index.js"]

Docker Compose

Docker Compose· Define multi-container app.
version: "3.9"
services:
  app:
    build: .
    ports:
      - "3000:3000"
    depends_on:
      - db
  db:
    image: postgres:16-alpine
Compose up· Launch all services.
docker compose up -d

Cleanup

System prune· Remove all unused resources.
docker system prune -a --volumes