我是Docker的新手。我正在尝试将我在ubuntu的anaconda3中创建的简单django应用程序进行docker化。
我的dockerfile看起来像这样:
# Pull base image
FROM continuumio/anaconda3
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# Set work directory
WORKDIR /code
COPY requirement.txt /code/
RUN conda install --file requirement.txt
# Copy project
COPY . /code/
requirement.txt
是我的conda虚拟环境中的依赖项软件包的列表。我通过在conda激活的环境中运行以下代码来获得该信息:
conda list -e > requirement.txt
而软件包django=3.0.3=py_0
在此requirement.txt
此外,这时,我已经正确安装了docker并提取了基础映像continuumio/anaconda3
。
这是我的docker-compose.yml
文件:
version: '3.8'
services:
web:
build: .
command: python /code/manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- 8000:8000
现在,当我运行docker-compose up
时,我收到了以下错误消息链(到此为止,requirement.txt
中的所有依赖包都已安装):
web_1 | Traceback (most recent call last):
web_1 | File "/code/manage.py", line 10, in main
web_1 | from django.core.management import execute_from_command_line
web_1 | ModuleNotFoundError: No module named 'django'
web_1 |
web_1 | The above exception was the direct cause of the following exception:
web_1 |
web_1 | Traceback (most recent call last):
web_1 | File "/code/manage.py", line 21, in <module>
web_1 | main()
web_1 | File "/code/manage.py", line 16, in main
web_1 | ) from exc
web_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?
hello_project_web_1 exited with code 1
我的问题:我做错了什么?码头工人为何要求激活虚拟环境?容器本身现在不是“虚拟环境”吗?
我看到了一个使用“ pip” here的有效示例。但是我习惯了conda,很想弄清楚这一点。
谢谢