I got following error while running from docker-compose but it works fine when I run docker run .
Can some body help me to debug this.
Error:
File "/home/desktop/.local/bin/docker-compose", line 5, in <module>
from compose.cli.main import main
File "/usr/lib/python3.10/site-packages/compose/cli/main.py", line 19, in <module>
from ..config import ConfigurationError
File "/usr/lib/python3.10/site-packages/compose/config/__init__.py", line 3, in <module>
from .config import ConfigurationError
File "/usr/lib/python3.10/site-packages/compose/config/config.py", line 48, in <module>
from .validation import match_named_volumes
File "/usr/lib/python3.10/site-packages/compose/config/validation.py", line 8, in <module>
from jsonschema import Draft4Validator
File "/usr/lib/python3.10/site-packages/jsonschema/__init__.py", line 21, in <module>
from jsonschema._types import TypeChecker
File "/usr/lib/python3.10/site-packages/jsonschema/_types.py", line 3, in <module>
from pyrsistent import pmap
ModuleNotFoundError: No module named 'pyrsistent'
My Dockerfile:
FROM python:3.9-alpine
ENV PYTHONUNBUFFERED=1
RUN apk update \
&& apk add --no-cache --virtual .build-deps
RUN pip install --upgrade pip
ENV APP_DIR /home/myapp
WORKDIR ${APP_DIR}
ADD requirements.txt ${APP_DIR}/
RUN pip install -r ${APP_DIR}/requirements.txt
COPY . .
EXPOSE 8000
ENTRYPOINT sh -c "python manage.py runserver 0.0.0.0:8000"
my docker compose file:
version: "3.9"
services:
web:
build:
context: .
volumes:
- .:/home/myapp
ports:
- "8000:8000"
command: python manage.py runserver 0.0.0.0:8000
container_name: django_myapp
restart: always
env_file: .env
While I run docker-compose build
I get above error. I have Tried adding pyrsistent in requirements.txt but error is still same. How to solve this error??
CodePudding user response:
This is a common Python error stack, you need to have some basic knowledge of Python to understand it, but I'll try to explain it briefly here.
The error starts with /home/desktop/.local/bin/docker-compose
which means it comes from docker-compose
on the host machine, not from inside Docker
. The call stack indicates a compose
-> jsonschema
-> pyrsistent
call path and pyrsistent
is not found (ModuleNotFoundError
), which means there's a missing dependency on your host machine.
Try pip3 install docker-compose --user
and pip3 install pyrsistent --user
:
/home/desktop/.local/bin/docker-compose
indicates your compose was installed to your home directory instead of the system path, so use--user
to try a local installation.- If everything works fine,
pip3 install docker-compose --user
will resolve the whole dependency tree and installpyrsistent
automatically. - If it doesn't work, try the second command to manual fix
pyrsistent
package. - If it still fails, try
pip3 install --force-reinstall --user pyrsistent
to reinstallpyrsistent
package.