Restarting Play application Docker container results in 'This application is already running' - RUNNING_PID is not deleted

I've just dockerized a Play! application and was also running into this issue - restarting the host caused the Play! application to fail to start in its container because RUNNING_PID had not been deleted.

It occurred to me that as the Play! application is the only process within its container, always has the same PID, and is taken care of by Docker, the RUNNING_PID file is (to the best of my knowledge) not actually needed.

As such I overrode pidfile.path to /dev/null by placing

javaOptions in Universal ++= Seq(
  "-Dpidfile.path=/dev/null"
)

in my project's build.sbt. And it works - I can reboot the host (and container) and my Play! application starts up fine.

The appeal for me of this approach is it does not require changing the way the image itself is produced by sbt-native-packager, just the way the application runs within it.

This works with sbt-native-packager 1.0.0-RC2 and higher (because that release includes https://github.com/sbt/sbt-native-packager/pull/510).


I sorted out a working workaround based on the answers and my further work on this question. If I start the containers as follows, they'll be up after an (un)expected stop/restart. The conflicting RUNNING_PID file won't prevent the container from restarting.

$ sudo docker run --restart=on-failure:5 -d \
--name container my_/container:latest \
sh -c "rm -f /var/run/play.pid && ./opt/bin/start \
-Dpidfile.path=/var/run/play.pid"

What it does is deleting the file containing the process ID which is put at a specific place using an option everytime before running the binary.


I don't know much about docker, but Play does not remove RUNNING_PID on stopping the server as far as I have tested. When I deployed my app in prod mode and try to stop it by Ctrl+D and Ctrl+C it din't remove the RUNNING_PID file from project directory so I had to manually delete it. From Play docs

Normally this(RUNNING_PID) file is placed in the root directory of your play project, however it is advised that you put it somewhere where it will be automatically cleared on restart, such as /var/run:

So - apart from manual deletion - the workaround is to change the path of RUNNING_PID and delete it every time the server starts through some script.

$ /path/to/bin/<project-name> -Dpidfile.path=/var/run/play.pid

Make sure that the directory exists and that the user that runs the Play application has write permission for it.

Using this file, you can stop your application using the kill command, for example:

$ kill $(cat /var/run/play.pid)

and you can also try docker command $ sudo docker rm --force redis

Maybe That could help

Source1 Source2 Source3