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.
Dockerfile:
FROM python
COPY ./app /app
WORKDIR /app
RUN pip install -r requirements.txt
EXPOSE 9003
CMD ["gunicorn", "-b", "0.0.0.0:9003", "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.
[Unit]
Description=Gunicorn instance to serve app
[Service]
WorkingDirectory=/home/app
ExecStart=gunicorn --workers 3 --bind 0.0.0.0:9003 unix:app.sock -m 007 main:app
Restart=always
[Install]
WantedBy=multi-user.target
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