Reputation: 311
I'm trying to run DjangoRQ workers inside a docker container - a simple 'worker' container which I will run on a digital ocean droplet. I'm using supervisord to run multiple workers.
Supervisord will run if I set the container command to sleep 3600
(so I can bash in before it crashes) then bash into the container and run supervisord -c supervisord.conf
. However, if I set the command on the container to that very same command, command: supervisord -c supervisord.conf
then the container exits saying 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
Upvotes: 1
Views: 1994
Reputation: 311
For anyone who hit this problem - the solution is frustratingly simple. You must run supervisord in the foreground or Docker doesn't think a process is running so it exits. Add the -n tag to supervisord and you'll be good to go.
worker:
build:
context: ./
dockerfile: DockerfileWorker
env_file:
- .env
environment:
- DJANGO_CONFIG
volumes:
- .:/dask
depends_on:
- postgres
- redis
command: supervisord -n -c supervisord.conf
Upvotes: 4