Use'systemctl' to manage process error in docker

Take over a Django project of the predecessor, this project uses supervisor for process management during deployment. To facilitate future deployment, I tried to package the project as a Docker image.
The contents of the Dockerfile are as follows:

FROM python:3.7

ENV PYTHONUNBUFFERED 1

RUN apt-get update \
    && apt-get -y install supervisor \
    && apt-get -y install systemd\
    && mkdir -p /home/project \
    && cd /home/project \
    && mkdir static \
    && mkdir media \
    && mkdir logs

COPY ./myproject/* /home/project/
COPY ./project.conf /etc/supervisor/conf.d
RUN pip install -r /home/project/requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple

WORKDIR /home/project

RUN systemctl restart supervisor.service

The project code is in the myproject directory of the host.
This image first installs supervisor and systemd;
secondly, creates a project directory in the container and creates a log directory under the directory;
again copies the code in the host to the project directory in the container and copies the supervisor configuration file in the host to the supervisor of the container In the configuration directory;
then install the project dependencies, and configure the domestic pip source mirror;
then specify the working directory in the container as project/, that is, the subsequent commands are executed in this directory;
finally restart the supervisor to load the copied configuration file.
Generate a mirror:

$ docker build -t apollo_docker .

But the last step of generating the image is wrong:

Step 8/8 : RUN systemctl restart supervisor.service
 ---> Running in 78350c856c39
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
The command '/bin/sh -c systemctl restart supervisor.service' returned a non-zero code: 1

The reason is that RUN calls bash/, and supervisor needs init/ to call, so you can change the latter command to

CMD ["/usr/sbin/init" "systemctl" "restart supervisor.service"]

Create again:

$ docker build -t apollo_docker .
Sending build context to Docker daemon  36.47MB
...
...
Successfully tagged apollo_docker:latest

Created successfully.

Guess you like

Origin blog.csdn.net/JosephThatwho/article/details/102943306