Search code examples
unixbuilddockersudoboot2docker

docker cannot start service from DockFile


In my dockerFile ,

I tried to do

service myapp start;

But when I start the container :

docker run -it myapp_image service myapp status 
>dead but pid file exists

However if I get into the conainer , and start it manually, it ran without problem

 docker run -it myapp_image /bin/bash
 bash-3.2$ service myapp restart
 bash-3.2$ service myapp status
        > myapp is running.

Any workaround to get the service running from DockerFile ?


Solution

  • service myapp start will start your app as a service in the background. As soon as this command exists, the docker container will stop. This is the expected behavior for Docker containers.

    What you want to do is to have the CMD instruction start your app in the foreground instead of in the background.