尝试docker时我头疼很多, 但这是杀了我 我正在尝试在docker上安装django,但是它卡在了这一行:
Successfully installed asgiref-3.2.7 django-3.0.6 pytz-2020.1 sqlparse-0.3.1
Dockerfile:
FROM python:3.6
COPY . /app
WORKDIR /app
CMD chmod +x entry.s
# ENTRYPOINT ["./entry.sh"] # this will give me, ./entry.sh: Permission denied
ENTRYPOINT ["sh", "./entry.sh"]
entry.sh:
echo entry point for django image
cd code
pip install -r requirements.txt
# for keep container running, I couldn't find any other way
touch app.log
tail -f app.log
docker run输出:
entry point for django image
Collecting django
Downloading Django-3.0.6-py3-none-any.whl (7.5 MB)
Collecting sqlparse>=0.2.2
Downloading sqlparse-0.3.1-py2.py3-none-any.whl (40 kB)
Collecting pytz
Downloading pytz-2020.1-py2.py3-none-any.whl (510 kB)
Collecting asgiref~=3.2
Downloading asgiref-3.2.7-py2.py3-none-any.whl (19 kB)
Installing collected packages: sqlparse, pytz, asgiref, django
Successfully installed asgiref-3.2.7 django-3.0.6 pytz-2020.1 sqlparse-0.3.1
--> stuck here
答案 0 :(得分:2)
如我所见,在entry.sh
中,您创建了一个空日志文件,并将其尾随。因此没有回应。而是运行django服务器:
# remove the log tailing file
python manage.py migrate
python manage.py runserver 0.0.0.0:8000
现在,在构建过程中安装依赖项是一个好习惯。这样,它将减少您运行docker容器的时间。泊坞窗还可以将这些安装缓存在层中,因此可以减少构建时间。因此,我建议像这样创建Dockerfile
:
FROM python:3.6
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
EXPOSE 8000
CMD python manage.py migrate;python manage.py runserver 0.0.0.0:8000
无需为此实施创建入口点。如果要检查日志,请检查Docker的documentation。这是有关如何执行此操作的示例:
docker logs -f <container name>