Devcontainer workspace
The Dev Container example provides a shared editor-hosted workspace for Frappe development. It combines one long-running development container with database and service containers, mounts the repository into a known path, and lets the editor manage ports and tools in a consistent way.
Workspace model
The workspace has two layers. Docker Compose supplies the development environment and its supporting services. The Dev Containers configuration tells the editor which Compose service to open, where the code is mounted, which user and tools to use, and how to manage the service lifecycle.
The example is copied to .devcontainer before the editor opens the repository in a container. This keeps the example available as a starting point while allowing a working checkout to choose its own local settings.
Development container
The frappe service is the interactive development environment. It stays running so the editor can attach to it, and its working directory is /workspace/development, which gives benches a stable location inside the mounted repository.
The editor opens this service as user frappe. A post-create step installs pre-commit, while the editor settings provide a Bash terminal and a small set of tools for Python, Vue, formatting, linting, SQL access, and spreadsheet inspection.
References: devcontainer-example/docker-compose.yml• L43-55 devcontainer-example/devcontainer.json• L21-46 devcontainer-example/devcontainer.json• L67-71
Supporting services
Compose starts the services that a local bench needs beside the development container. MariaDB is the default database. Separate Redis services provide cache and queue roles so application work and background work use the same service boundaries as the development setup.
PostgreSQL, Mailpit, and a Cypress UI test container are optional paths in the example. They remain disabled until a developer enables the matching service for a specific development need.
The service names form the local network contract. The development container can reach the database and Redis services by their Compose names without publishing those service ports to the host.
References: devcontainer-example/docker-compose.yml• L1-41 devcontainer-example/docker-compose.yml• L56-82
Editor integration
The Dev Containers configuration makes the Compose environment feel like one local project. The editor attaches to the frappe service, treats the mounted repository as the workspace, and stops the Compose project when the workspace closes.
Repository mount
The repository root is mounted at /workspace. The editor then selects /workspace/development as its workspace folder. This arrangement separates the container's tools from the checkout while giving benches a stable path that can be shared by terminal work, debugging, and interactive sessions.
The host SSH directory is mounted into the frappe user's home directory. This supports work with private Git repositories when the developer chooses to use host SSH credentials.
References: devcontainer-example/docker-compose.yml• L47-55 devcontainer-example/devcontainer.json• L67-74 docs/…/01-development.md• L66-69
Port forwarding
The editor exposes the ports used by a running bench instead of the Compose file publishing them directly. Port 8000 serves the Frappe web interface. Port 9000 serves realtime traffic. Port 6787 serves the asset watcher.
The port labels and forwarding rules make the web interface visible to the host while keeping realtime and asset-watcher traffic available to the development tools. Other ports are ignored unless a developer explicitly forwards them.
The following diagram shows how editor forwarding connects host tools to processes inside the workspace.
flowchart LR
Host[Developer host] --> Editor[Dev Containers editor]
Editor -->|8000| Web[Frappe web process]
Editor -->|9000| Realtime[Frappe realtime process]
Editor -->|6787| Watcher[Asset watcher]
Web --> App[Bench in frappe service]
Realtime --> App
Watcher --> App
References: devcontainer-example/devcontainer.json• L3-20 docs/…/01-development.md• L379-392
Editor lifecycle
Reopening the repository in a container causes the editor to start the Compose project and attach to frappe. Closing the workspace stops that project through shutdownAction, which prevents the development services from remaining active after the editor session ends.
The editor's automatic port forwarding and restored forwarded ports reduce host-specific setup. The workspace still depends on Docker having enough memory and on the selected database and optional services matching the bench configuration.
References: devcontainer-example/devcontainer.json• L3-4 devcontainer-example/devcontainer.json• L35-46 devcontainer-example/devcontainer.json• L67-71 docs/…/01-development.md• L7-16
Development flow
The workspace supports a short path from checkout to an interactive Frappe bench. The editor owns the container session, while the developer creates and runs benches inside the mounted development folder.
Workspace creation
A developer copies devcontainer-example to .devcontainer, opens the repository in VS Code, and selects Dev Containers: Reopen in Container. The editor reads the local Dev Container configuration and uses its Compose file to create the workspace services.
The database choice is made before the workspace starts. MariaDB is the default. PostgreSQL requires changing the local Compose configuration and aligning the bench setup with that choice.
References: docs/…/01-development.md• L25-64 devcontainer-example/devcontainer.json• L67-70 devcontainer-example/docker-compose.yml• L2-20
Bench operation
After the container is ready, the developer creates benches inside /workspace/development. A bench uses the MariaDB or PostgreSQL service and the Redis roles supplied by Compose. The resulting web, realtime, watcher, scheduler, and worker processes use the forwarded editor ports and the shared local services.
For debugging, the developer can start the bench processes through the editor rather than treating the container as a single opaque process. This keeps the same Compose services in place while allowing the editor to control the processes that need inspection.
The flow below shows the boundary between workspace setup and bench work.
sequenceDiagram
participant Dev as Developer
participant Editor as Dev Containers editor
participant Compose as Compose project
participant Frappe as frappe service
participant Services as Database and Redis services
Dev->>Editor: Reopen repository in container
Editor->>Compose: Start development services
Compose-->>Editor: Attach to frappe service
Dev->>Frappe: Create or open a bench
Frappe->>Services: Use database, cache, and queue roles
Frappe-->>Editor: Serve web, realtime, and watcher ports
Editor-->>Dev: Forward development endpoints
References: docs/…/01-development.md• L66-75 docs/…/01-development.md• L266-278 docs/…/01-development.md• L316-344 devcontainer-example/docker-compose.yml• L37-55
Workspace boundaries
The example standardizes the shape of a development session but does not lock every input to one immutable build. The frappe service uses the frappe/bench:latest image, while the database and Redis images use the versions shown in the Compose example.
The repository root compose.yaml is a separate application service stack. It coordinates application configuration with web, realtime, worker, scheduler, and site-data services for a running application. The editor-hosted workspace instead uses the Compose file copied from devcontainer-example, so changes to the root stack do not by themselves change the Dev Container service graph.
The configuration is for development only. Its sample database password is shared by the example and must not be treated as a production credential. Production deployments use the repository's separate deployment configurations.
Service extension points
Developers can extend the workspace when a feature needs another local dependency. Mailpit supports local outgoing-mail checks. PostgreSQL supports database-specific work. Cypress supports browser-based UI checks when the host display setup is also prepared.
Each extension changes the local service graph. The developer must enable the service and then rebuild or reopen the Dev Container so the editor and Compose project use the same graph.
References: devcontainer-example/docker-compose.yml• L14-35 devcontainer-example/docker-compose.yml• L56-82 compose.yaml• L19-103 docs/…/01-development.md• L395-403
Related pages
- Development environment provisioning — broader development environment setup.
- Development installer and app configuration — bench and app setup after the workspace is available.
- Container stack architecture — application service stack and its runtime boundaries.
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the Dev Container service name, Compose service name, and editor workspace folder aligned. A mismatch can leave the editor attached to the wrong service or path.
- Keep the database and Redis service names aligned with the bench connection settings. Compose can still start while the bench cannot connect.
- Treat changes to forwarded ports as a contract change for local URLs, realtime access, and asset watching.
- Review optional service changes together with the host setup they require, such as display access for Cypress or credentials for private Git sources.
- Review image tag changes for reproducibility. The current bench image uses a moving
latesttag. - Keep changes to the root application stack separate from the Dev Container Compose graph. The editor attaches to the copied example service rather than the root compose.yaml services.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
The editor opens the repository without the copied .devcontainer configuration | The standard Compose workspace is not selected | Copy devcontainer-example to .devcontainer before reopening in the container |
| The bench expects PostgreSQL while the default MariaDB service remains active | Bench setup or site access fails against the wrong database type | Select the database before workspace creation and update the local Compose services together |
| A process uses a port that is not forwarded or a host port is already in use | The web interface or development tool is not reachable from the host | Keep process ports and Dev Container forwarding rules aligned; resolve host port conflicts |
| An optional service is enabled without its host prerequisites | Mail, browser UI tests, or another dependent feature cannot run | Apply the service-specific setup before rebuilding or reopening the workspace |
| The moving bench image changes upstream | A new workspace can behave differently from an earlier one | Pin the image tag when repeatable image content is required |
| The editor is pointed at the root application stack instead of the Dev Container Compose file | The expected interactive frappe workspace service is not available | Keep dockerComposeFile pointed at the copied Dev Container example |
Key files
| File | Why to read it |
|---|---|
| devcontainer-example/devcontainer.json | Defines the editor-facing workspace contract, including the Compose service, workspace path, user, ports, tools, and lifecycle. |
| devcontainer-example/docker-compose.yml | Defines the development container and the database, cache, queue, and optional local services that support it. |
| compose.yaml | Defines the separate application service stack and clarifies its boundary from the editor-hosted workspace. |
| docs/…/01-development.md | Describes how engineers create the local Dev Container workspace and operate benches inside it. |
| docs/…/04-alternate-setup.md | Explains the boundary between the intended editor-hosted setup and direct CLI use of the same Compose example. |