Docker Community Forums

Share and learn in the Docker community.

Create linux service with systemd inside docker container

Created flask application and deploying on gunicorn server on docker.
I want to write shell script to create linux service inside docker container, so I can start, stop and restart my flask app inside container.


FROM python
COPY ./app /app
RUN pip install -r requirements.txt
CMD ["gunicorn", "-b", "", "main:app"]

Build it and run using command : docker run -p 9003:9003 myapp.

What I have tried opened docker container cli: docker exec -it <container_id> bash . You can find container id by command docker ps.

Step 1: changed directory to /etc/init.d and created myservice.service file.

Description=Gunicorn instance to serve app

ExecStart=gunicorn --workers 3 --bind unix:app.sock -m 007 main:app


step 3: I enable service by first running cd /etc/rc3.d and then run ln -s ../init.d/{SERVICENAME} S95{SERVICENAME}

step 4: Give permission : chmod +x /etc/init.d/{SERVICENAME}
step 5: start service : `service myservice start

But this give me error
enter image description here

Docker container OS: Debian 10

Why its giving me Unit not found? any idea? How to resolve?

Reference: startup - How do services in Debian work, and how can I manage them? - Unix & Linux Stack Exchange

Also posted on create linux service with systemd inside docker container - Stack Overflow.