Environment Information:
-
System: Windows 11 + WSL2 (Ubuntu 22.04)
-
Deployment: Docker Compose source code deployment
-
Requirement: Run mathematical modeling code in Sandbox (requires
networkxandpulp+ system-level solversglpk/cbc).
Problem Description: I customized the sandbox image and modified docker-compose.yml, but now I’m stuck in a bizarre “error loop” where I cannot simultaneously satisfy dependency existence and sufficient permissions:
Core Contradiction (The Loop):
-
State A: Error “ModuleNotFoundError”
-
When I rebuild the image to ensure libraries exist, the web interface reports missing libraries.
-
However, when I enter the container via
docker execto check, the libraries are present.
-
-
State B: Error “error: operation not permitted”
-
To resolve the PuLP solver permission issue, I configured
security_opt: seccomp:unconfinedandprivileged: trueindocker-compose.yml. -
Once permissions seem to take effect (or after restarting the service to refresh the configuration), the error changes to “No module named ‘networkx’”.
-
If I manage to make the libraries discoverable, the code fails again at
prob.solve()with “operation not permitted”.
-
My Configuration:
1. Dockerfile.sandbox (as follows)
FROM langgenius/dify-sandbox:latest
USER root
RUN apt-get update && apt-get install -y coinor-cbc glpk-utils
RUN pip install --no-cache-dir --default-timeout=1000 -i https://mirrors.aliyun.com/pypi/simple/ \
numpy \
pandas \
scipy
RUN pip install --no-cache-dir --default-timeout=1000 -i https://mirrors.aliyun.com/pypi/simple/ \
networkx \
pulp \
scikit-opt \
statsmodels \
scikit-learn \
scienceplots \
openpyxl
2. docker-compose.yml (ensuring permissions are relaxed)
sandbox:
image: my-math-sandbox:local
container_name: docker-sandbox-1
restart: always
privileged: true
security_opt:
- seccomp:unconfined
- apparmor:unconfined
cap_add:
- SYS_PTRACE
Verified Facts:
-
Image builds correctly: Tested with
docker run --rm -it my-math-sandbox:local python3 -c "import pulp; print('ok')", both libraries and solvers work normally. -
Container is running:
docker psconfirms the sandbox is indeed loading themy-math-sandbox:localimage. -
Exec tests succeed: While the container is running, manually executing scripts via
docker exec -it docker-sandbox-1 python3works perfectly, with no permission errors or missing library errors.
Core Question: Why does the Dify Web UI (Go Runner) execution environment behave so differently from the environment I enter via docker exec?
-
Does Dify’s Runner ignore
security_optfrom Docker Compose when launching Python processes? -
Or does enabling privileged mode cause the Runner to mount a different filesystem, rendering my
pip installineffective?
Please kindly advise on troubleshooting directions! I’ve been stuck in this loop for two days.