liveBook · Manning

Development Dockerfile

As explained in Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform

A development Dockerfile is a Dockerfile used to build a container image with a configuration optimized for software development.

A development Dockerfile builds a container image for fast software iteration rather than production performance or security. Keep it beside a production Dockerfile so each configuration can serve its own purpose without drifting too far apart. section 5.5.3

A development Dockerfile typically:

  • Installs all npm dependencies, including development dependencies. section 5.5.3
  • Leaves source code outside the image so Docker Compose can mount it into the running container. section 5.5.4
  • Uses a shared npm cache to make container recreation and subsequent installs faster. section 5.5.4

Minimal development Dockerfile

FROM node:18.5.0 WORKDIR /usr/src/app COPY package*.json ./ CMD npm install --prefer-offline && npm run start:dev

Listing 5.5 Updating the Docker Compose file for live reload
version: '3'
services:
 
  --snip--
 
  history:                                     #1
    image: history
    build: 
      context: ./history
      dockerfile: Dockerfile-dev               #2
    container_name: history
    volumes:                                   #3
      - /tmp/history/npm-cache:/root/.npm:z    #4
      - ./history/src:/usr/src/app/src:z       #5
    ports:
     - "4002:80"
    environment:
      - PORT=80
      - NODE_ENV=development
    restart: "no"

Configure Docker Compose to select Dockerfile-dev, mount the source directory for live reload, and persist the npm cache outside the container. section 5.5.4

How Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform covers it

How deep it goes
Explains the Dockerfile structure, dependency choice, startup command, and Compose volumes, but stops short of production deployment details.
Examples
Uses a Node.js 18.5.0 Dockerfile and a Docker Compose service mounting source code and an npm cache.
What it assumes
Assumes familiarity with Dockerfiles, Docker Compose, Node.js, npm, and containerized microservices.
What you can do after
Operate/configure Docker Compose to run a service with development dependencies, live reload, and a retained npm cache.
How it connects
Connects Docker Compose, Docker volumes, npm dependencies, live reload, and production Dockerfiles.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform. The section links point to the parts of the book it draws on.