使用 Docker 启动主管并在 docker 日志中查看其日志,但未在容器中找到具有服务主管状态的服务

Starting supervisor with Docker and seeing its logs in docker logs, but not finding the service with service supervisor status in the container

我想 运行 supervisor 在同一个容器中有多个进程,因为我不能在我们当前的托管环境中使用 docker-compose。当我查看 docker 日志时,一切似乎都正常,但是当我将终端连接到容器时,我在 linux 系统中看不到主管服务。

当我检查容器的日志时,我得到:

Starting supervisord.... (entrypoint.sh)
2021-12-22 08:38:50,871 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.
2021-12-22 08:38:50,877 INFO RPC interface 'supervisor' initialized
2021-12-22 08:38:50,877 CRIT Server 'inet_http_server' running without any HTTP authentication checking
2021-12-22 08:38:50,878 INFO supervisord started with pid 1

但是,如果我将 shell 附加到容器和 运行“服务主管状态”,我会得到:

supervisord is not running.

而且我不明白为什么系统似乎无法识别该服务 运行ning。谁能帮我解决这个问题,因为如果我不能从终端访问该服务,我就无法以任何方式真正管理它。

这是我的 Dockerfile

FROM python:3.8
ENV PYTHONUNBUFFERED 1

RUN apt-get update
RUN apt-get install -y pgbouncer
RUN apt-get update && apt-get install -y supervisor

# install nginx
ENV NGINX_VERSION 1.15.12-1~stretch
ENV NJS_VERSION   1.15.12.0.3.1-1~stretch
RUN set -x \
    && \
    NGINX_GPGKEY=573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62; \
    found=''; \
    for server in \
        hkp://keyserver.ubuntu.com:80 \
        hkp://p80.pool.sks-keyservers.net:80 \
        pgp.mit.edu \
    ; do \
        echo "Fetching GPG key $NGINX_GPGKEY from $server"; \
        apt-key adv --keyserver "$server" --keyserver-options timeout=10 --recv-keys "$NGINX_GPGKEY" && found=yes && break; \
    done; \
    test -z "$found" && echo >&2 "error: failed to fetch GPG key $NGINX_GPGKEY" && exit 1; \
    apt-get remove --purge --auto-remove -y gnupg1 && rm -rf /var/lib/apt/lists/* \
    && dpkgArch="$(dpkg --print-architecture)" \
    && nginxPackages=" \
        nginx=${NGINX_VERSION} \
        nginx-module-xslt=${NGINX_VERSION} \
        nginx-module-geoip=${NGINX_VERSION} \
        nginx-module-image-filter=${NGINX_VERSION} \
        nginx-module-njs=${NJS_VERSION} \
    " \
    && echo "deb https://nginx.org/packages/mainline/debian/ stretch nginx" >> /etc/apt/sources.list.d/nginx.list \
    && apt-get update \
    && apt-get install --no-install-recommends --no-install-suggests -y \
                        $nginxPackages \
                        gettext-base \
    && rm -rf /var/lib/apt/lists/* /etc/apt/sources.list.d/nginx.list


# install app
RUN mkdir /var/app && chown www-data:www-data /var/app
WORKDIR /var/app
COPY ./requirements.txt /var/app/
RUN pip install -r requirements.txt
COPY . /var/app/

COPY ./conf/nginx/staging.conf /etc/nginx/conf.d/default.conf
COPY ./conf/pgbouncer/pgbouncer.ini /etc/pgbouncer/pgbouncer.ini
COPY ./supervisord.conf /etc/supervisor/conf.d/supervisord.conf

VOLUME /var/logs

# Expose ports (Added from previous dockerfile)
EXPOSE 80 2222 

# Added for setting right permissions to entrypoint script 
RUN ["chmod", "+x", "./entrypoint.sh"]
RUN ["chmod", "+x", "/var/app/bin/staging/django-q.sh"]

ENTRYPOINT ["./entrypoint.sh"]

这是我的 entrypoint.sh - 我首先为 pg-bouncer 设置一些设置,然后启动 supervisor

#!/bin/bash

set -e

# SET UP PG BOUNCER
PG_CONFIG_DIR=/etc/pgbouncer

invoke_main(){
    check_variables
    create_config
}

check_variables(){
    ...
}

error(){
  ...
}

create_databases_config(){
 ...
}

create_config(){
 ... 
}

[databases]
$(create_databases_config)

[pgbouncer]
...

invoke_main

# INVOKE SUPERVISORD
echo " Starting supervisord.... (entrypoint.sh)"
exec supervisord -n -c /etc/supervisor/conf.d/supervisord.conf
#exec supervisord -n -c /etc/supervisor/conf.d/supervisord.conf

这是我的supervisord.conf

[supervisord]
logfile=/var/logs/supervisord.log   ; main log file; default $CWD/supervisord.log
logfile_maxbytes=50MB               ; max main logfile bytes b4 rotation; default 50MB
logfile_backups=10                  ; # of main logfile backups; 0 means none, default 10
loglevel=info                       ; log level; default info; others: debug,warn,trace
pidfile=/var/logs/supervisord.pid
nodaemon=true                       ; Run interactivelly instead of deamonizing
# user=www-data

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[inet_http_server]
port = 127.0.0.1:9001

[supervisorctl]
serverurl = http://127.0.0.1:9001

您正在手动启动 supervisordservice 命令无法正确报告其状态。