Rails tmp/pids/server.pid not cleaned Up

Well, isn’t this embarrassing. Unfortunately, Compose has a couple of irritating issues. Since you may have encountered them in the preceding chapters, or as you go on to use Compose yourself, it seems irresponsible to ignore them. Here we will take a quick look at each in turn.

Fortunately, we can work around the first issue with a little effort. For some reason, occasionally upon terminating the app with Compose (pressing Ctrl+C), the Rails server doesn’t seem to shut down cleanly, and it’s server.pid file which Rails stores in tmp/pids/ is not deleted. This means that upon starting the app again, you may find yourself confronted by the following error in the output:

$ docker-compose up
...
A server is already running. Check /usr/src/app/tmp/pids/server.pid
...

The existence of the pid file makes the Rails server starting up believe that there is a server already running, so it won’t launch. Rails saves the server.pid file in tmp/pids. Since we are mounting our local app directory into the container, the file ends up in the tmp/pids/ directory on our local machine and is persisted until we delete it.

Get hands-on with 1200+ tech skills courses.