From 66ce39eb18b5a7dc1e24170a64930e87742583dc Mon Sep 17 00:00:00 2001 From: "daniel.radl" Date: Mon, 3 Aug 2026 19:37:59 +0200 Subject: [PATCH] fix(devcontainer): rely on VS Code port forwarding --- devcontainer-example/devcontainer.json | 22 ++++++++++++++++++ devcontainer-example/docker-compose.yml | 4 +--- docs/05-development/01-development.md | 2 +- docs/05-development/04-alternate-setup.md | 28 +++++++++++++++++++---- 4 files changed, 48 insertions(+), 8 deletions(-) diff --git a/devcontainer-example/devcontainer.json b/devcontainer-example/devcontainer.json index 060f534..c3bf8b0 100644 --- a/devcontainer-example/devcontainer.json +++ b/devcontainer-example/devcontainer.json @@ -1,6 +1,24 @@ { "name": "Frappe Bench", "forwardPorts": [8000, 9000, 6787], + "portsAttributes": { + "8000-8099": { + "label": "Frappe web", + "protocol": "http", + "onAutoForward": "notify" + }, + "9000-9099": { + "label": "Frappe realtime", + "onAutoForward": "silent" + }, + "6787": { + "label": "Frappe asset watcher", + "onAutoForward": "silent" + } + }, + "otherPortsAttributes": { + "onAutoForward": "ignore" + }, "remoteUser": "frappe", "customizations": { "vscode": { @@ -15,6 +33,10 @@ "charliermarsh.ruff" ], "settings": { + "remote.autoForwardPorts": true, + "remote.autoForwardPortsSource": "process", + "remote.restoreForwardedPorts": true, + "remote.localPortHost": "localhost", "terminal.integrated.profiles.linux": { "frappe bash": { "path": "/bin/bash" diff --git a/devcontainer-example/docker-compose.yml b/devcontainer-example/docker-compose.yml index bf3bbf7..ef84eed 100644 --- a/devcontainer-example/docker-compose.yml +++ b/devcontainer-example/docker-compose.yml @@ -52,9 +52,7 @@ services: # Enable if you require git cloning # - ${HOME}/.ssh:/home/frappe/.ssh working_dir: /workspace/development - ports: - - 8000-8005:8000-8005 - - 9000-9005:9000-9005 + # Development ports are forwarded by devcontainer.json. # enable the below service if you need Cypress UI Tests to be executed # Before enabling ensure install_x11_deps.sh has been executed and display variable is exported. # Run install_x11_deps.sh again if DISPLAY is not set diff --git a/docs/05-development/01-development.md b/docs/05-development/01-development.md index df22e4b..ecdcc06 100644 --- a/docs/05-development/01-development.md +++ b/docs/05-development/01-development.md @@ -378,7 +378,7 @@ The first command can take a few seconds to be executed, this is to be expected. ## Manually start containers -In case you don't use VSCode, you may start the containers manually with the following command: +The example configuration forwards development ports through VS Code and does not publish them through Docker. If you don't use VS Code, first follow the [CLI-only port configuration](04-alternate-setup.md#configure-ports-for-cli-only-use), then start the containers manually: ### Running the containers diff --git a/docs/05-development/04-alternate-setup.md b/docs/05-development/04-alternate-setup.md index d202747..3de09e8 100644 --- a/docs/05-development/04-alternate-setup.md +++ b/docs/05-development/04-alternate-setup.md @@ -66,6 +66,24 @@ This gives you `.devcontainer/docker-compose.yml` which defines all the services - `redis-cache` — cache layer - `redis-queue` — background job queue +### Configure ports for CLI-only use + +The example configuration is intended for VS Code Dev Containers and forwards development ports through VS Code. Because this setup runs Docker Compose directly, add the following environment variable and loopback-only port mappings to the `frappe` service in `.devcontainer/docker-compose.yml`: + +```yaml +services: + frappe: + # ... existing config + environment: + - SHELL=/bin/bash + - FRAPPE_BIND_ADDR=0.0.0.0 + ports: + - "127.0.0.1:8000-8005:8000-8005" + - "127.0.0.1:9000-9005:9000-9005" +``` + +Frappe's development server binds to `127.0.0.1` by default. `FRAPPE_BIND_ADDR=0.0.0.0` makes it reachable through Docker's port mappings, while binding the published ports to `127.0.0.1` keeps them accessible only from your local machine. + --- ## Step 4 — Add ARM64 Platform to All Services @@ -121,16 +139,18 @@ Error response from daemon: failed to set up container networking: driver failed - Check if the port is being used by another service with `lsof -i :PORT` > Usually on MacOS ports 8000 and 9000 are usually reserved for system use -- Go to line 60 and 61 under the `frappe` service and change the ports +- Change the host-side port ranges under the `frappe` service Eg: -``` +```yaml ports: - - 8001-8005:8001-8005 - - 9002-9005:9002-9005 + - "127.0.0.1:8100-8105:8000-8005" + - "127.0.0.1:9100-9105:9000-9005" ``` +With this example, open the first site on port `8100` instead of `8000`. + --- ## Step 6 — Enter the Development Container