A Docker volume stores or shares files outside a container’s ordinary filesystem. In development, it connects the host filesystem to a container so code edited in VS Code appears quickly in the running microservice. section 5.5.4
Use Docker volumes to:
- Mount source code directly into a development container instead of baking it into the image. section 5.5.4
- Persist the npm cache on the host so recreating a container can make later package installation faster. section 5.5.4
- Remove volumes with docker compose down --volumes when a clean application restart is required. section 4.3.5
Mount source and npm cache with Compose
Configure the development service with Dockerfile-dev and two volumes: /tmp/history/npm-cache:/root/.npm:z preserves the npm cache, while ./history/src:/usr/src/app/src:z shares source code. With live reload, edits on the host can reload the microservice without rebuilding and restarting the whole application. section 5.5.4 section 5.11
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"
Inspect the complete Compose extract showing the development image, volume mappings, ports, environment, and restart policy. section 5.5.4
Stopping containers does not remove them, and restarting can restore their old filesystem state. For a clean development reset, run docker compose down --volumes; combine it with docker compose up --build when rebuilding is also needed. section 4.3.5



