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
