我正在尝试使用Docker构建一个Django应用程序。我的应用程序将在本地服务器上运行,但是当我尝试使用docker进行迁移时,它会抛出Module Not Found错误。这是我的requirements.txt
djangorestframework==3.7.0
Django==1.11.5
#import_export==0.5.1
django-csvimport==2.2
psycopg2
这是我的docker-compose.yml`。
docker-compose.yml
version: '3'
services:
web:
build: .
command: python djangorest/manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
这是我的Dockerfile
FROM python:3.6
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
#COPY . /code/
RUN pip install -r requirements.txt
ADD . /code/
当我通过此cmd docker-compose运行web python djangorest / manage.py migrate
时出现以下错误docker-compose run web python djangorest/manage.py migrate
Traceback (most recent call last):
File "djangorest/manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 338, in execute
django.setup()
File "/usr/local/lib/python3.6/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python3.6/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/usr/local/lib/python3.6/site-packages/django/apps/config.py", line 120, in create
mod = import_module(mod_path)
File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'csvimport'
这是我的settings.py文件
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'api',
'csvimport.app.CSVImportConf',
'import_export',
]
我不知道我的代码有什么问题,或者我在这里想念一些东西。