python - 使用 docker-compose 'command:' 运行时,Supervisord 退出 Docker 容器,但从 bash 运行时不会退出
问题描述
我正在尝试在 docker 容器中运行 DjangoRQ 工作人员 - 一个简单的“工作人员”容器,我将在数字海洋水滴上运行。我正在使用 supervisord 来运行多个工作人员。
如果我将容器命令设置为sleep 3600
(这样我可以在它崩溃之前 bash 进入),Supervisord 就会运行,然后 bash 进入容器并运行supervisord -c supervisord.conf
. 但是,如果我将容器上的命令设置为相同的命令,command: supervisord -c supervisord.conf
则容器退出时说Unlinking stale socket /tmp/supervisor.sock
worker:
build:
context: ./
dockerfile: DockerfileWorker
env_file:
- .env
environment:
- DJANGO_CONFIG
volumes:
- .:/dask
depends_on:
- postgres
- redis
command: sleep 3600
# `python-base` sets up all our shared environment variables
FROM ubuntu:latest
# python
ENV PYTHONUNBUFFERED=1 \
# prevents python creating .pyc files
PYTHONDONTWRITEBYTECODE=1 \
\
# pip
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
\
# poetry
# https://python-poetry.org/docs/configuration/#using-environment-variables
POETRY_VERSION=1.1.5 \
# make poetry install to this location
POETRY_HOME="/opt/poetry" \
# make poetry create the virtual environment in the project's root
# it gets named `.venv`
POETRY_VIRTUALENVS_IN_PROJECT=true \
# do not ask any interactive question
POETRY_NO_INTERACTION=1 \
\
# paths
# this is where our requirements + virtual environment will live
PYSETUP_PATH="/opt/pysetup" \
VENV_PATH="/opt/pysetup/.venv" \
LOG_LEVEL=DEBUG
# prepend poetry and venv to path
ENV PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH"
RUN apt-get update \
&& apt-get install --no-install-recommends -y \
# deps for installing poetry
curl \
# deps for building python deps
build-essential \
python3-pip
# install poetry - respects $POETRY_VERSION & $POETRY_HOME
RUN pip3 install poetry
# copy project requirement files here to ensure they will be cached.
WORKDIR $PYSETUP_PATH
COPY poetry.lock pyproject.toml ./
# install runtime deps - uses $POETRY_VIRTUALENVS_IN_PROJECT internally
RUN poetry install --no-dev
# # `production` image used for runtime
# FROM python-base as production
COPY . /dask
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
WORKDIR /dask
解决方案
对于遇到此问题的任何人 - 解决方案非常简单。您必须在前台运行 supervisord ,否则 Docker 认为没有进程正在运行,因此它会退出。将 -n 标签添加到 supervisord,你会很高兴的。
worker:
build:
context: ./
dockerfile: DockerfileWorker
env_file:
- .env
environment:
- DJANGO_CONFIG
volumes:
- .:/dask
depends_on:
- postgres
- redis
command: supervisord -n -c supervisord.conf
推荐阅读
- python - SQLAlchemy AttributeError:“AsyncEngine”对象没有属性“_run_ddl_visitor”
- javascript - Socket io 似乎一直在恢复 pollin
- mongodb - 将新字段添加到 MongoDB 中的集合,但值基于另一个字段中的值
- ios - 有没有办法在 Swift 5(核心蓝牙)中发现的外围设备列表中删除重复的外围设备
- flutter - 颤振-'initialValue == null || 控制器 == null':不正确。表单小部件中的错误
- go - 如何使用 GIO 库使窗口居中
- powershell - Powershell在脚本中使用数组中的字符串
- haskell - 具有自定义类型的 Haskell Church 数字
- json - 如何将 Cytoscape 网络保存为平面 JSON?
- reactjs - 输入'{孩子:ReactNode; }' 与类型 'IntrinsicAttributes' 没有共同的属性