I am trying to run a custom service in a docker container. The service is started with myservice start
- this then forks and daemonises the main process and exits. The main process then listens on a network socket for incoming commands. The process itself works fine.
In my Dockerfile, I have this as the last two commands:
WORKDIR "/app/myservice"
CMD ["bin/myservice", "start"]
The image is built successfully. Now, when I run it like so:
docker run -d -p 7890:7890 myimage
the container starts and then exits. In logs, I can see the service starting prior to the container exiting with exit code 0. This is expected, as the command from the dockerfile exits with code 0.
Looking at this question, it seems apparent that if I run it like so:
docker run -dit -p 7890:7890 myimage
the container should stay running even after the batch script that starts my service exits. Yet this is not the case - and the container terminates exits straight away.
What am I missing? How can I get the container to stay running?