Skip
Arish's avatar

19. Bind Mounts for Development


Development Workflow

Bind mounts let you see code changes instantly.

bash
1# Mount source code
2docker run -v $(pwd):/app -p 3000:3000 myapp

Rails Development

bash
1docker run -it --rm \
2  -v $(pwd):/app \
3  -v bundle-cache:/usr/local/bundle \
4  -p 3000:3000 \
5  ruby:3.2 \
6  bash -c "cd /app && bundle install && rails server -b 0.0.0.0"

Node.js Development

bash
1docker run -it --rm \
2  -v $(pwd):/app \
3  -v /app/node_modules \
4  -p 3000:3000 \
5  node:18 \
6  npm run dev

Note: -v /app/node_modules creates anonymous volume to preserve container's node_modules.

File Permissions

bash
1# Run as current user
2docker run -u $(id -u):$(id -g) -v $(pwd):/app myapp

Docker Compose Example

yaml
1services:
2  app:
3    build: .
4    volumes:
5      - .:/app
6      - bundle-cache:/usr/local/bundle
7    ports:
8      - "3000:3000"
9
10volumes:
11  bundle-cache: