Frappe_docker build aborts with "ModuleNotFoundError: No module named 'redis.commands'"

The error occurs in building “FROM base AS builder” in the step

RUN export APP_INSTALL_ARGS="" && \
  if [ -n "${APPS_JSON_BASE64}" ]; then \
    export APP_INSTALL_ARGS="--apps_path=/opt/frappe/apps.json"; \
  fi && \
  bench init ${APP_INSTALL_ARGS}\
    --frappe-branch=${FRAPPE_BRANCH} \
    --frappe-path=${FRAPPE_PATH} \
    --no-procfile \
    --no-backups \
    --skip-redis-config-generation \
    --verbose \
    /home/frappe/frappe-bench && \
  cd /home/frappe/frappe-bench && \
  echo "{}" > sites/common_site_config.json && \
  find apps -mindepth 1 -path "*/.git" | xargs rm -fr

at the “bench build” part:

Done in 5.37s.
Done in 70.36s.
WARN: restart failed: Couldn't find supervisorctl in PATH
$ bench build
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 114, in <module>
    main()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 20, in main
    click.Group(commands=commands)(prog_name="bench")
  File "/home/frappe/frappe-bench/env/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/frappe/frappe-bench/env/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/home/frappe/frappe-bench/env/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/frappe/frappe-bench/env/lib/python3.11/site-packages/click/core.py", line 1685, in invoke
    super().invoke(ctx)
  File "/home/frappe/frappe-bench/env/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/frappe/frappe-bench/env/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/frappe/frappe-bench/env/lib/python3.11/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 44, in app_group
    ctx.obj = {"sites": get_sites(site), "force": force, "verbose": verbose, "profile": profile}
                        ^^^^^^^^^^^^^^^
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 56, in get_sites
    elif default_site := frappe.get_conf().default_site:
                         ^^^^^^^^^^^^^^^^^
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 452, in get_conf
    with init_site(site):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 462, in __enter__
    init(self.site)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 306, in init
    setup_redis_cache_connection()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 482, in setup_redis_cache_connection
    from frappe.utils.redis_wrapper import setup_cache
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/redis_wrapper.py", line 7, in <module>
    from redis.commands.search import Search
ModuleNotFoundError: No module named 'redis.commands'
subprocess.CalledProcessError: Command 'bench build' returned non-zero exit status 1.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/bench/commands/make.py", line 75, in init
    init(
  File "/usr/local/lib/python3.11/site-packages/bench/utils/render.py", line 105, in wrapper_fn
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/bench/utils/system.py", line 112, in init
    build_assets(bench_path=path)
  File "/usr/local/lib/python3.11/site-packages/bench/utils/bench.py", line 380, in build_assets
    exec_cmd(command, cwd=bench_path, env=env)
  File "/usr/local/lib/python3.11/site-packages/bench/utils/__init__.py", line 178, in exec_cmd
    raise CommandFailedError(cmd) from subprocess.CalledProcessError(return_code, cmd)
bench.exceptions.CommandFailedError: bench build

ERROR: There was a problem while creating /home/frappe/frappe-bench
Do you want to rollback these changes? [y/N]: Aborted!
The command '/bin/sh -c export APP_INSTALL_ARGS="" &&   if [ -n "${APPS_JSON_BASE64}" ]; then     export APP_INSTALL_ARGS="--apps_path=/opt/frappe/apps.json";   fi &&   bench init ${APP_INSTALL_ARGS}    --frappe-branch=${FRAPPE_BRANCH}     --frappe-path=${FRAPPE_PATH}     --no-procfile     --no-backups     --skip-redis-config-generation     --verbose     /home/frappe/frappe-bench &&   cd /home/frappe/frappe-bench &&   echo "{}" > sites/common_site_config.json &&   find apps -mindepth 1 -path "*/.git" | xargs rm -fr' returned a non-zero code: 1

real    12m24,149s
user    0m0,547s
sys     0m4,588s

The build script is the following one (taken from a working example from @revant_one, and only slightly modified):

$ cat build.sh
git clone https://github.com/frappe/frappe_docker

cd frappe_docker

# Add apps to apps.json
nano apps.json

export APPS_JSON_BASE64=$(base64 -w 0 ./apps.json)



echo "Building started at $(date)" > ../build.log
df -h >> ../build.log
df >> ../build.log
diff apps.json frappe_docker/apps.json >> ../build.log


sudo docker build \
  --build-arg=FRAPPE_PATH=https://github.com/frappe/frappe \
  --build-arg=FRAPPE_BRANCH=v15.42.0 \
  --build-arg=PYTHON_VERSION=3.11.9 \
  --build-arg=NODE_VERSION=20.17.0 \
  --build-arg=APPS_JSON_BASE64=$APPS_JSON_BASE64 \
  --tag=erpnext-bivo:v0.0.1 \
  --file=images/custom/Containerfile . \
  | tee -a ../build.log

The apps.json I used is:

$ cat frappe_docker/apps.json
[
{
“url”: “GitHub - frappe/erpnext: Free and Open Source Enterprise Resource Planning (ERP)”,
“branch”: “v15.42.0”
},
{
“url”: “GitHub - frappe/insights: Open Source Business Intelligence Tool”,
“branch”: “v3.0.7”
},
{
“url”: “GitHub - frappe/builder: Craft beautiful websites effortlessly with an intuitive visual builder and publish them instantly”,
“branch”: “v1.12.5”
},
{
“url”: “GitHub - frappe/erpnext-shipping: A Shipping Integration for ERPNext”,
“branch”: “v15.0.2”
},
{
“url”: “GitHub - frappe/wiki: Free and Open Source Wiki built on top of Frappe”,
“branch”: “v2.0.1”
},
{
“url”: “GitHub - The-Commit-Company/raven: Simple, open source team messaging platform”,
“branch”: “v1.7.0”
}
]

This was “just now” (in the last 2-3 hours).
I’m still trying to bisect where the problem must have occured, but trying more recent versions of the frappe and erpnext apps (with those I started, going back to versions of a known-good build script as alluded to above) yielded the same results. I also tried apps.json containing more apps, but reduced it already to what’s above.
I can go on with this for a while, but I’m also suspecting a problem elsewhere:

Was there a change which put the newest frappe_docker build script out of sync with these apps?

Or maybe something else which appears clear to somebody reading this?

Try removing wiki and insights.

Try adding apps one after another, only if the added one works.

I remember wiki needs master branch and insights needed develop branch of frappe.