我有一个正在运行的Ubuntu Docker容器,该容器安装了python3.7,mongodb和超级用户。当我尝试通过超级用户服务运行python脚本时,会引发以下错误:
supervisor: couldn't exec /data/code/venvs/cleverInvest/bin/python: ENOEXEC
supervisor: child process was not spawned
supervisor.conf
[supervisord]
;logfile=/var/app/logs/ ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=5 ; (num of main logfile rotation backups;default 10)
loglevel=debug ; (log level;default info; others: debug,warn,trace)
pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=true ; (start in foreground if true;default false)
minfds=1024 ; (min. avail startup file descriptors;default 1024)
minprocs=200 ; (min. avail process descriptors;default 200)
[program:mongod]
;command=/usr/bin/mongod --config /etc/mongod.conf
command=/usr/bin/mongod
stdout_logfile=/var/log/supervisor/%(program_name)s.log
stderr_logfile=/var/log/supervisor/%(program_name)s.log
autorestart=true
user=mongodb
priority=100
[program:server]
priority=10
;directory=/data/code/
;command=python3 server.py
command=/data/code/venvs/cleverInvest/bin/python /data/code/server.py
user=root
autostart=true
autorestart=true
[program:cleverinvest]
priority=10
;directory=/data/code/
command=/data/code/venvs/cleverInvest/bin/python /data/code/main.py
;command=python3 main.py
user=root
autostart=true
autorestart=true
我已经尝试将!#/bin/sh
添加到python文件中,或者给它们指定777规则。似乎没有任何帮助。
这是我的Dockerfile
FROM ubuntu:latest
MAINTAINER Docker
# Update apt-get sources AND install MongoDB
RUN apt-get update && apt-get upgrade -y
RUN apt-get install -y software-properties-common
RUN apt install -y gnupg2
RUN gpg2 --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys F3B1AA8B
# Installation:
RUN add-apt-repository ppa:deadsnakes/ppa
RUN apt-get install -y python3.7
RUN apt-get install -y python3-pip
#Mongodb
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
RUN apt-add-repository 'deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse'
RUN apt-get update
RUN apt-get install -y mongodb-org
# Supervisor for starting multiple process in Docker
RUN apt-get -y install supervisor && \
mkdir -p /var/log/supervisor && \
mkdir -p /etc/supervisor/conf.d
ADD supervisor.conf /etc/supervisor.conf
# Create the MongoDB data directory
RUN mkdir -p /data/db
RUN chmod 777 /data/db
# Create the MongoDB data directory
RUN mkdir -p /data/code
RUN chmod 777 /data/code
RUN mongod --version
#RUN mongod --dbpath /data/db --fork --logpath /data/db/log
# COPY cleverInvest Code to Container
COPY dev /data/code
# Installing pip for python modules
RUN apt-get install -y python3-pip
# Install modules
WORKDIR /data/code/
RUN chmod +x -R *.py
RUN chmod 777 -R *
RUN pip3 install -r requirements.txt
RUN pip3 freeze
EXPOSE 80 27017
# Set /usr/bin/mongod as the dockerized entry-point application
CMD ["supervisord", "-c", "/etc/supervisor.conf"]
#ENTRYPOINT ["/bin/bash"]
答案 0 :(得分:0)
所以我自己弄清楚了,我想写我的解决方案,以防别人遇到同样的问题。
我只是使用全局安装的python版本而不是通过virtualenv来更改启动python脚本的方法。 所以我的supervisor.conf文件现在看起来像这样:
[supervisord]
;logfile=/var/app/logs/ ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=5 ; (num of main logfile rotation backups;default 10)
loglevel=debug ; (log level;default info; others: debug,warn,trace)
pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=true ; (start in foreground if true;default false)
minfds=1024 ; (min. avail startup file descriptors;default 1024)
minprocs=200 ; (min. avail process descriptors;default 200)
[program:mongod]
;command=/usr/bin/mongod --config /etc/mongod.conf
command=/usr/bin/mongod
stdout_logfile=/var/log/supervisor/%(program_name)s.log
stderr_logfile=/var/log/supervisor/%(program_name)s.log
autorestart=true
user=mongodb
priority=100
[program:server]
priority=10
directory=/data/code/
command=python3 server.py
;command=/data/code/venvs/cleverInvest/bin/python /data/code/server.py
user=root
autostart=true
autorestart=true
[program:cleverinvest]
priority=10
directory=/data/code/
command=python3 main.py
;command=/data/code/venvs/cleverInvest/bin/python /data/code/main.py
user=root
autostart=true
autorestart=true
我的脚本文件中也出现语法错误。纠正它们之后,它就起作用了。