DevContainer/Docker Compose/Concept/Using Docker Compose
Properties
- tags
- DevContainer, Docker, Docker/Compose, Diataxis/Explanation
Using Docker Compose with DevContainers Conceptual Overview
Overview
- Dev Containers supports Docker Compose for managing multi-container development environments, allowing developers to reference existing
docker-compose.ymlfiles and extend them with development-specific configurations. - This enables seamless integration between production Docker Compose configurations and development container setups without modifying production files.
- Dev Containers supports Docker Compose for managing multi-container development environments, allowing developers to reference existing
Context
- Many projects already use Docker Compose to define their multi-container production environments.
- Developers need to add development-specific configurations (like volume mounts, debugging capabilities, and extended runtime configurations) without altering production compose files.
- Docker Compose's override mechanism provides a clean way to layer development configurations on top of production setups.
Key Principles
- Production File Preservation: Never modify production
docker-compose.ymlfiles for development purposes. - Sequential File Processing: VS Code processes Docker Compose files in the order specified in
dockerComposeFilearray. - Service Selection: The
serviceproperty indevcontainer.jsonspecifies which service from the compose file to use as the dev container. - Workspace Mapping: The
workspaceFolderproperty defines where source code is mounted inside the container.
- Production File Preservation: Never modify production
Mechanism
Examples
Best Practices
Misconceptions
- Override files replace the base file → False. Override files supplement and extend the base configuration through Docker Compose's merge behavior.
- All services in the compose file are started → False. Only the specified service and its dependencies are started.
- Production compose files must be modified for development → False. Use override files to keep production configurations pristine.
- Volume mounts are automatic → False. You must explicitly define volume mounts in your compose or override files.
Related
- DevContainer
- DevContainer/Docker Compose/How To/Create Override File
- DevContainer/Feature/Concept/Docker Build Order
- Docker/Compose/How To/Remove Volumes