Can't install devcontainer using frappe docker (python env error)

I’m trying to use a dev container to build my own apps. But I’ve spend the last two weeks failing to open the dev container. I’ve just tried again from scratch. I can correcty copy the repo for frappe docker. I can also go into the devcontainer via vscode but bench isn’t working. When I run bench init i get the following : Setting Up Environment
$ python3 -m venv env
$ /workspace/development/habitudes/env/bin/python -m pip install --quiet --upgrade pip
$ /workspace/development/habitudes/env/bin/python -m pip install --quiet wheel
/bin/sh: 1: redis-server: not found
Traceback (most recent call last):
File “/home/frappe/.bench/bench/commands/make.py”, line 75, in init
init(
File “/home/frappe/.bench/bench/utils/render.py”, line 105, in wrapper_fn
return fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File “/home/frappe/.bench/bench/utils/system.py”, line 70, in init
bench.setup.config(
File “/home/frappe/.bench/bench/utils/render.py”, line 126, in wrapper_fn
return fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File “/home/frappe/.bench/bench/bench.py”, line 386, in config
generate_config(self.bench.name)
File “/home/frappe/.bench/bench/config/redis.py”, line 15, in generate_config
redis_version = get_redis_version()
^^^^^^^^^^^^^^^^^^^
File “/home/frappe/.bench/bench/config/redis.py”, line 73, in get_redis_version
version_string = subprocess.check_output(“redis-server --version”, shell=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/frappe/.pyenv/versions/3.11.6/lib/python3.11/subprocess.py”, line 466, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/frappe/.pyenv/versions/3.11.6/lib/python3.11/subprocess.py”, line 571, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command ‘redis-server --version’ returned non-zero exit status 127.

ERROR: There was a problem while creating habitudes ;

I also get the following problem in python output : 2025-01-08 12:59:56.385 [error] [
‘getActivatedEnvironmentVariables, Class name = M, completed in 24ms, has a falsy return value, Arg 1: Uri:/workspace/development, Arg 2: undefined, Arg 3: undefined, Arg 4: “/bin/bash”’,
l [Error]: Failed to resolve env “/workspace/development/frappe-bench/env/bin/python”
at ae (/home/frappe/.vscode-server/extensions/ms-python.python-2024.22.2-linux-x64/out/client/extension.js:2:2036206)
at oe (/home/frappe/.vscode-server/extensions/ms-python.python-2024.22.2-linux-x64/out/client/extension.js:2:2034166)
at Immediate. (/home/frappe/.vscode-server/extensions/ms-python.python-2024.22.2-linux-x64/out/client/extension.js:2:2030460)
at processImmediate (node:internal/timers:483:21) {
code: -4,
data: undefined
}
]
2025-01-08 12:59:56.385 [error] Failed to apply terminal env vars undefined l [Error]: Failed to resolve env “/workspace/development/frappe-bench/env/bin/python”
at ae (/home/frappe/.vscode-server/extensions/ms-python.python-2024.22.2-linux-x64/out/client/extension.js:2:2036206)
at oe (/home/frappe/.vscode-server/extensions/ms-python.python-2024.22.2-linux-x64/out/client/extension.js:2:2034166)
at Immediate. (/home/frappe/.vscode-server/extensions/ms-python.python-2024.22.2-linux-x64/out/client/extension.js:2:2030460)
at processImmediate (node:internal/timers:483:21) {
code: -4,
data: undefined
}
2025-01-08 12:59:56.385 [error] Python Extension: interpreterManager.refresh l [Error]: Failed to resolve env “/workspace/development/frappe-bench/env/bin/python”
at ae (/home/frappe/.vscode-server/extensions/ms-python.python-2024.22.2-linux-x64/out/client/extension.js:2:2036206)
at oe (/home/frappe/.vscode-server/extensions/ms-python.python-2024.22.2-linux-x64/out/client/extension.js:2:2034166)
at Immediate. (/home/frappe/.vscode-server/extensions/ms-python.python-2024.22.2-linux-x64/out/client/extension.js:2:2030460)
at processImmediate (node:internal/timers:483:21) {
code: -4,
data: undefined
}
2025-01-08 12:59:56.386 [error] [
‘Failed to activate a workspace, Class name = v, completed in 1376ms, has a falsy return value, Arg 1: Uri:/workspace/development/installer.py, Arg 2: {“started”:1736341194348}, Return Value: undefined’,
l [Error]: Failed to resolve env “/workspace/development/frappe-bench/env/bin/python”
at ae (/home/frappe/.vscode-server/extensions/ms-python.python-2024.22.2-linux-x64/out/client/extension.js:2:2036206)
at oe (/home/frappe/.vscode-server/extensions/ms-python.python-2024.22.2-linux-x64/out/client/extension.js:2:2034166)
at Immediate. (/home/frappe/.vscode-server/extensions/ms-python.python-2024.22.2-linux-x64/out/client/extension.js:2:2030460)
at processImmediate (node:internal/timers:483:21) {
code: -4,
data: undefined
}
]
2025-01-08 12:59:56.386 [error] Failure during activation. l [Error]: Failed to resolve env “/workspace/development/frappe-bench/env/bin/python”
at ae (/home/frappe/.vscode-server/extensions/ms-python.python-2024.22.2-linux-x64/out/client/extension.js:2:2036206)
at oe (/home/frappe/.vscode-server/extensions/ms-python.python-2024.22.2-linux-x64/out/client/extension.js:2:2034166)
at Immediate. (/home/frappe/.vscode-server/extensions/ms-python.python-2024.22.2-linux-x64/out/client/extension.js:2:2030460)
at processImmediate (node:internal/timers:483:21) {
code: -4,
data: undefined
}
2025-01-08 12:59:56.386 [error] sendStartupTelemetry() failed. l [Error]: Failed to resolve env “/workspace/development/frappe-bench/env/bin/python”
at ae (/home/frappe/.vscode-server/extensions/ms-python.python-2024.22.2-linux-x64/out/client/extension.js:2:2036206)
at oe (/home/frappe/.vscode-server/extensions/ms-python.python-2024.22.2-linux-x64/out/client/extension.js:2:2034166)
at Immediate. (/home/frappe/.vscode-server/extensions/ms-python.python-2024.22.2-linux-x64/out/client/extension.js:2:2030460)
at processImmediate (node:internal/timers:483:21) {
code: -4,
data: undefined
} ;

Please help me I’m tired of struggling…

I recently prepared an unattended script to setup a development container on Docker Windows. Use it as a reference

  1. Install Docker Desktop
  2. Enable WSL2 then restart
wsl --install
  1. In frappe-docker/docker-compose.yml

# docker-compose.yml
services:
  mariadb:
    image: mariadb:10.6
    command:
      - --character-set-server=utf8mb4
      - --collation-server=utf8mb4_unicode_ci
      - --skip-character-set-client-handshake
      - --skip-innodb-read-only-compressed
    environment:
      MYSQL_ROOT_PASSWORD: 123
      MYSQL_ROOT_HOST: '%'
    volumes:
      - mariadb-data:/var/lib/mysql
    ports:
      - "3307:3306"

  redis-cache:
    image: redis:alpine
    ports:
      - "13000:6379"

  redis-queue:
    image: redis:alpine
    ports:
      - "11000:6379"

  redis-socketio:
    image: redis:alpine
    ports:
      - "12000:6379"

  frappe:
    image: frappe/bench:latest
    command: sleep infinity
    user: "1000:1000"
    environment:
      - SHELL=/bin/bash
      - CHOKIDAR_USEPOLLING=true
    volumes:
      - ./scripts:/workspace/scripts
      - ./frappe-bench:/workspace/frappe-bench
    working_dir: /workspace
    ports:
      - "8000-8005:8000-8005"
      - "8080:8080"
      - "9000-9005:9000-9005"
    depends_on:
      - mariadb
      - redis-cache
      - redis-queue
      - redis-socketio

volumes:
  mariadb-data:

  1. In frappe-docker/scripts/init.sh:
#!/bin/bash

set -e

# Setup NodeJS
source /home/frappe/.nvm/nvm.sh
nvm alias default 18
nvm use 18
echo "nvm use 18" >> ~/.bashrc

# Wait for MariaDB to be ready
echo "Waiting for MariaDB to be ready..."
until mysql -h mariadb -u root -p123 -e "SELECT 1" >/dev/null 2>&1
do
    echo "MariaDB is unavailable - sleeping"
    sleep 1
done

echo "MariaDB is up - proceeding with setup"

# Initialize Frappe Bench
cd /workspace
sudo chown -R frappe:frappe frappe-bench
bench init \
--ignore-exist \
--skip-redis-config-generation \
frappe-bench

cd frappe-bench

# Configure Redis and MariaDB hosts
bench set-mariadb-host mariadb
bench set-redis-cache-host redis-cache:6379
bench set-redis-queue-host redis-queue:6379
bench set-redis-socketio-host redis-socketio:6379

# Remove redis from Procfile
sed -i '/redis/d' ./Procfile

# Create new site
echo "Creating new site..."
bench new-site dev.localhost \
--mariadb-root-password 123 \
--admin-password admin \
--no-mariadb-socket

bench --site dev.localhost set-config developer_mode 1
bench --site dev.localhost clear-cache
bench use dev.localhost

echo "Setup complete! You can now start developing with Frappe."

  1. Fix line endings for init through powershell in docker directory
$content = Get-Content -Path "scripts\init.sh" -Raw
$content = $content -replace "`r`n", "`n"
Set-Content -Path "scripts\init.sh" -Value $content -NoNewline
  1. Start the containers
docker-compose up -d
  1. Run initialization script
docker-compose exec frappe bash /workspace/scripts/init.sh

To access development environment and use bench

docker-compose exec frappe bash
cd frappe-bench

Then,

bench start

To login;

http://localhost:8000/app
Login credentials:
Username: Administrator
Password: admin

For front-end development, port 8080 is already open with CHOKIDAR_USEPOLLING enabled for vite. Simply run the following at your frappe-ui/doppio frontend

yarn dev --host

You might also need to ignore CSRF for frontend development

bench --site dev.localhost set-config ignore_csrf 1

You can include this in the initialization script if you plan to always use your docker dev for frontend development.

Hello Yamen_Zakhour,

Thank you so much for sharing your unattended script for setting up the development container. I followed your instructions, and the installation worked perfectly! I truly appreciate the effort you put into detailing every step.

I do have a question regarding the frontend development part. You mentioned running yarn dev --host at the frappe-ui/doppio frontend. However, in my setup, I don’t have a frappe-ui directory. Could you clarify where exactly I should execute this command?

Please excuse the level of my questions, as I’m still a beginner in this field, but I’m eager to learn more!

Thank you again for your guidance!

Best regards,
Maël

EDIT : I’ve tried to modify the git origin so I can push changes on my own repo, but it seems like I’ve broken everything… I added my remote origin, stashed the changes, changed branch and pushed. What I would like to do is create an app and use git only to commit the changes of my own app, not all of frappe.

Because of my mistake (I think I checked out the changes which caused this error), I now get the following when trying to run the bench : 09:29:07 socketio.1 | node:internal/modules/cjs/loader:1080
09:29:07 socketio.1 | throw err;
09:29:07 socketio.1 | ^
09:29:07 socketio.1 |
09:29:07 socketio.1 | Error: Cannot find module ‘/workspace/frappe-bench/apps/frappe/socketio.js’
09:29:07 socketio.1 | at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
09:29:07 socketio.1 | at Module._load (node:internal/modules/cjs/loader:922:27)
09:29:07 socketio.1 | at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:86:12)
09:29:07 socketio.1 | at node:internal/main/run_main_module:23:47 {
09:29:07 socketio.1 | code: ‘MODULE_NOT_FOUND’,
09:29:07 socketio.1 | requireStack:
09:29:07 socketio.1 | }
09:29:07 socketio.1 |
09:29:07 socketio.1 | Node.js v18.18.2

This is not a dev container example, its a custom app example. I will prepare and share a dev container step by step guideline. Hope it helps.

I’m not sure I understand the difference between a dev container and a custom app dev container… And I feel like your tutorial is more about setting up erp next in a production environment isn’t it ?

By the way, I managed to get frappe running again by deleting the frappe-bench dir and then running the init script again. I then tried to follow this advice to push my work in my repo : I'm not able to ( git push) files in apps folder, at first it didn’t work because of what was in the repo. So i replaced the last command with a git push --force origin main and it did work with a few modifications I was even able to run the unit testing. Thanks a lot for your help.

The purpose of dev-containers as suggested by documentation is to be able to develop ERPNext apps and push those changes in their own repos. If you have not decided yet on developing, the production env is just fine.