Docker:python3 manage.py runserver错误

时间:2019-12-09 10:31:28

标签: python django docker

我正在使用Docker,但遇到问题。

错误:

WARNING: Image for service django was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Creating develserver_db_1     ... done
Creating develserver_django_1 ... done
Attaching to develserver_django_1, develserver_db_1
django_1  | Traceback (most recent call last):
django_1  |   File "manage.py", line 10, in main
django_1  |     from django.core.management import execute_from_command_line
django_1  | ModuleNotFoundError: No module named 'django'
django_1  | 
django_1  | The above exception was the direct cause of the following exception:
django_1  | 
django_1  | Traceback (most recent call last):
django_1  |   File "manage.py", line 21, in <module>
django_1  |     main()
django_1  |   File "manage.py", line 12, in main
django_1  |     raise ImportError(
django_1  | ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
develserver_django_1 exited with code 1
db_1      | 
db_1      | PostgreSQL Database directory appears to contain a database; Skipping initialization
db_1      | 
db_1      | 2019-12-09 10:01:20.171 UTC [1] LOG:  starting PostgreSQL 12.1 (Debian 12.1-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1      | 2019-12-09 10:01:20.172 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1      | 2019-12-09 10:01:20.172 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db_1      | 2019-12-09 10:01:20.175 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1      | 2019-12-09 10:01:20.234 UTC [27] LOG:  database system was interrupted; last known up at 2019-12-07 09:01:08 UTC
db_1      | 2019-12-09 10:01:23.250 UTC [27] LOG:  database system was not properly shut down; automatic recovery in progress
db_1      | 2019-12-09 10:01:23.295 UTC [27] LOG:  redo starts at 0/1646188
db_1      | 2019-12-09 10:01:23.295 UTC [27] LOG:  invalid record length at 0/16461C0: wanted 24, got 0
db_1      | 2019-12-09 10:01:23.295 UTC [27] LOG:  redo done at 0/1646188
db_1      | 2019-12-09 10:01:23.407 UTC [1] LOG:  database system is ready to accept connections

Dockerfile:

FROM python:3
RUN apt update
RUN apt-get install  postgresql-contrib -y
RUN apt-get install musl-dev -y
RUN apt-get install libpq-dev gcc
RUN apt-get install python3-dev -y
RUN export PATH=/usr/lib/postgresql/X.Y/bin/:$PATH
RUN pip3 install psycopg2-binary
RUN pip3 install psycopg2


# Delete build dependencies 
# RUN apk del .build-deps
ENV PYTHONUNBUFFERED 0
RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/
RUN pip3 install -r requirements.txt
COPY . /code/
CMD source develvenv/bin/activate

起初,我以为虚拟环境是问题

所以,我尝试添加CMD source develvenv/bin/activate,但错误仍然没有消失。.

据我所知,这种错误不是Django本身的问题。我认为虚拟环境会引起问题。

你的主意如何?

0 个答案:

没有答案