Featured image of post Introduction to local development environment built with Docker containersFeatured image of post Introduction to local development environment built with Docker containers

Introduction to local development environment built with Docker containers

Do you install runtimes (Node.js, Python, Ruby, etc.) and databases (PostgreSQL, MySQL) directly on the host OS every time you try a new programming language or framework? “OS environment contamination” that worries you about version conflicts and garbage files during uninstallation will become a thing of the past if you use Docker containers. We organize the steps to build a practical local development environment in a hands-on format.

Why can’t you install it directly into the host OS?

Version conflicts such as Project A requires Python 3.10 and Project B requires Python 3.12 are commonplace. Docker allows you to isolate your application execution environment and middleware as independent, disposable containers. Even when you get a new PC, you can instantly recreate a perfect development environment by cloning the repository and hitting a single command.

Practice: Minimum configuration of web application + DB compose.yaml

The following is an example of a standard compose.yaml that links a Node.js environment and a PostgreSQL database.

services:
  app:
    build: .
    ports:
      - "3000:3000"
    volumes:
      - .:/app
      - /app/node_modules
    environment:
      - DATABASE_URL=postgres://devuser:devpass@db:5432/devdb
    depends_on:
      - db

  db:
    image: postgres:16-alpine
    restart: always
    environment:
      POSTGRES_USER: devuser
      POSTGRES_PASSWORD: devpass
      POSTGRES_DB: devdb
    volumes:
      - db-data:/var/lib/postgresql/data
    ports:
      - "5432:5432"

volumes:
  db-data:

Two major tips for smooth development

  1. Hot reload and volume mount: Bind mount the current directory (.:/app) into the container in order to immediately reflect changes in the source code on the host side. However, the key is to protect the node_modules and virtual environment inside the container with an anonymous volume so that they are not overwritten with empty folders on the host side.
  2. Using VS Code Dev Containers: By combining the editor extension “Dev Containers”, you can start VS Code itself in a container and seamlessly use the container-side completion engine and linter with the same operational feel as the host.

Get a clean, reproducible development platform and focus on writing code.