8.3.2 Dev Bind Mounts
A focused guide to Dev Bind Mounts, connecting core concepts with practical Docker and container operations.
Dev bind mounts are bind mounts specifically used during local development to connect a project's source code or configuration directly into a running container, enabling a fast development feedback loop without needing to rebuild an image for every small change.
The Basic Development Pattern
A project's source directory is bind-mounted directly into the container at the location the application expects to find its code.
docker run -d -v $(pwd):/app -p 3000:3000 node:20-alpine sh -c "cd /app && npm install && npm run dev"
Edits made to source files on the host, using whatever editor or IDE the developer prefers, are immediately reflected inside the running container.
Combining Dev Bind Mounts With a Development-Specific Compose File
A Compose file specifically intended for local development commonly defines this kind of bind mount as part of its configuration.
services:
app:
build: .
volumes:
- .:/app
ports:
- "3000:3000"
command: npm run dev
Why Dev Bind Mounts Differ From Production Configuration
The same application's production deployment typically does not use a bind mount for its source code at all, instead relying on the application code being baked directly into the built image — dev bind mounts are specifically a development-time convenience, not a production pattern.
COPY . .
In production, this COPY instruction bakes the application code into the image itself, in contrast to development's bind-mounted approach.
Avoiding Common Pitfalls With Dependency Directories
Bind-mounting an entire project directory can sometimes inadvertently overwrite a node_modules (or equivalent) directory installed inside the container with the host's potentially different or absent version, requiring a separate, excluded volume specifically for dependencies.
volumes:
- .:/app
- /app/node_modules
Why Dev Bind Mounts Matter
This pattern is one of the most valuable everyday applications of bind mounts, providing a fast, convenient development workflow that closely mirrors a containerized production environment while still allowing the immediate, iterative editing experience developers expect.