【发布时间】:2020-05-24 09:08:22
【问题描述】:
我的docker文件如下:
#Use python 3.6 image
FROM python:3.6
ENV PYTHONUNBUFFERED 1
#install required packages
RUN apt-get update
RUN apt-get install libsasl2-dev libldap2-dev libssl-dev python3-dev psmisc -y
#install a pip package
#Note: This pip package has a completely configured django project in it
RUN pip install <pip-package>
#Run a script
#Note: Here appmanage.py is a file inside the pip installed location(site-packages), but it will be accessible directly without cd to the folder
RUN appmanage.py appconfig appadd.json
#The <pip-packge> installed comes with a built in django package, so running it with following CMD
#Note: Here manage.py is present inside the pip package folder but it is accesible directly
CMD ["manage.py","runserver","0.0.0.0:8000"]
当我跑步时:
sudo docker build -t test-app .
dockerfile 中的步骤直到:RUN appmanage.py appconfig 按预期成功运行,但之后出现错误:
The command '/bin/sh -c appmanage.py appconfig ' returned a non-zero code: 137
当我在谷歌上搜索错误时,我得到的建议是内存不足。但我已经验证,系统(centos)有足够的内存。
附加信息
RUN appmanage.py appconfig 执行过程中的命令行输出为:
Step 7/8 : RUN appmanage.py appconfig
---> Running in 23cffaacc81f
======================================================================================
configuring katana apps...
Please do not quit (or) kill the server manually, wait until the server closes itself...!
======================================================================================
Performing system checks...
System check identified no issues (0 silenced).
February 08, 2020 - 12:01:45
Django version 2.1.2, using settings 'katana.wui.settings'
Starting development server at http://127.0.0.1:9999/
Quit the server with CONTROL-C.
9999/tcp:
20Killed
【问题讨论】:
-
wait until the server closes itself...--> 可能是服务器自己关闭时,返回码137?一种检查方法是在您的工作环境中运行appmanage.py appconfig appAdd.json,等待服务器自行终止并在此之后立即打印出状态代码:echo $?。只要返回状态码为 !== 0,docker build就会失败。 -
我不会让服务器退出。脚本(appmanage.py)就是这样做的。我将无法自定义脚本,因为它属于我正在安装的 pip 包(观察 dockerfile)。当我看到脚本的源代码时,我发现脚本正在运行
os.system("fuser -k 9999/tcp")以杀死服务器 -
是的,我知道脚本(appmanage.py)是使服务器退出的脚本。当这种情况发生时,它可能会返回一个非零状态码,从而导致
docker build命令失败。 -
我不确定你想用这个
appmanage.py appconfig appAdd.json达到什么目的。是从另一个项目中提取或复制过来的吗?你能用 bash 或 python 脚本来简化它,而不是创建一个服务器并杀死它吗?总的来说,只需要确保每个RUN都会成功退出,代码为0! -
好的,我明白了。当我下周可以访问我的电脑时,我会尝试自己构建它!
标签: python django docker pip dockerfile