用户警告:Supervisord正在以root身份运行,并在默认位置搜索其配置文件。

9

我已经构建了一个docker镜像docker build -t ds_backend .,其中所有配置都在以下错误之后提到。

尝试使用docker run ds_backend运行镜像时,出现以下错误。

/usr/lib/python2.7/dist-packages/supervisor/options.py:461: UserWarning: Supervisord is running as root and it is searching for its configuration file in default locations (including its current working directory); you probably want to specify a "-c" argument specifying an absolute path to a configuration file for improved security.
  'Supervisord is running as root and it is searching '
2020-08-27 01:53:36,963 CRIT Supervisor is running as root.  Privileges were not dropped because no user is specified in the config file.  If you intend to run as root, you can set user=root in the config file to avoid this message.
2020-08-27 01:53:36,966 INFO supervisord started with pid 1

这是我的配置文件

Dockerfile

FROM python:3.6

MAINTAINER Dockerfiles

RUN mkdir /trell-ds-framework
WORKDIR /trell-ds-framework
ADD . /trell-ds-framework/
RUN python3 setup.py bdist_wheel
# install uwsgi now because it takes a little while
RUN pip3 install uwsgi
# copy over our requirements.txt file
# upgrade pip and install required python packages
RUN pip3 --no-cache-dir install -U pip
RUN apt-get install -y ca-certificates
RUN apt-get update && \
    apt-get install -y software-properties-common && \
    rm -rf /var/lib/apt/lists/*
# RUN add-apt-repository universe
RUN apt-get update
RUN apt-get install -y supervisor
RUN apt-get install -y ca-certificates supervisor
COPY supervisor_app.conf /etc/supervisor/conf.d/supervisord.conf
RUN apt-get update && apt-get -y install cron
RUN pip3 --no-cache-dir install -r requirements.txt
RUN python3 -c "import nltk;nltk.download('stopwords')"
# setup all the configfiles
# RUN echo "daemon off;" >> /etc/nginx/nginx.conf
# RUN /usr/sbin/nginx -g "daemon off;"
COPY nginx_app.conf /etc/nginx/sites-available/default
COPY supervisor_app.conf /etc/supervisor/conf.d/


# add (the rest of) our code

EXPOSE 80
# CMD ["supervisord"]
CMD ["/usr/bin/supervisord"]

supervisor_app.conf

[supervisord]
nodaemon=true
user=root


[program:uwsgi]
command = /usr/local/bin/uwsgi --ini /trell-ds-framework/uwsgi.ini
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

[program:nginx]
command = /usr/sbin/nginx -g "daemon off;"
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
daemon=off

nginx_app.conf

server {
    listen 80 default_server;
    server_name ip;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    location / {
        include uwsgi_params;
        uwsgi_pass unix:///trell-ds-framework/app.sock;
    }
}

uwsgi.ini 文件

[uwsgi]
callable = app
chdir = /trell-ds-framework
wsgi-file = /trell-ds-framework/wsgi.py
socket = /trell-ds-framework/app.sock
master = true
processes = 2
chmod-socket = 666
enable-threads = true
user=root
Can anybody guide me here if I am doing something wrong ? Any leads highly appreciated. Thanks.
2个回答

11

根据设计:

  • 如果未指定USER,docker容器将以root身份运行
  • 如果没有在配置文件中明确指定,supervisor将不允许以root身份运行daemon。

因此,您可以将supervisor作为非root用户运行,或者只需在配置文件中添加user=root指令。

[supervisord]
nodaemon=true
user=root


[program:uwsgi]
command = /usr/local/bin/uwsgi --ini /trell-ds-framework/uwsgi.ini
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
user=root

[program:nginx]
command = /usr/sbin/nginx -g "daemon off;"
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
daemon=off
user=root ;here too if you want to


嘿,感谢您的回答。我尝试过这个方法,但仍然出现相同的错误。Supervisor 正在以 root 身份运行。特权未被删除,因为配置文件中没有指定用户。如果您打算以 root 用户身份运行,则可以在配置文件中设置 user=root 以避免此消息。即使在配置文件中添加 user=root,仍会出现此警告。我们是否还漏掉了其他什么东西? - iamabhaykmr
尝试将用户root添加到服务中,并使用supervisor -c /etc/supervisor/conf.d/supervisor_app.conf显式指定配置文件位置。 - Iduoad
嗨lduoad,这是否应该在Docker容器内完成? - Emmanuel Spencer Egbuniwe
是的!你可以将它添加到你的 Dockerfile 中(将配置文件复制到你的容器镜像中),并在你的 ENTRYPOINT 中运行该命令。 - Iduoad

2

我曾经遇到过同样的问题。使用user=root和supervisord的-n(守护进程模式)帮助了我。

RUN echo user=root >>  /etc/supervisor/supervisord.conf
CMD ["/usr/bin/supervisord","-n"]

Marcjin,你把这个加到了 etc/supervisor.ini 文件里吗?请解释一下你是如何运行这个命令的或者它被添加到哪里了。我也遇到了同样的错误。 - Emmanuel Spencer Egbuniwe
如果您在Docker中使用supervisor,那么这就是您的解决方案: CMD ["/usr/bin/supervisord","-n"] - Yuukoo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接