Search⌘ K

Rails Server not starting?

Understand how to troubleshoot and fix the common issue where the Rails server fails to start in Docker due to the persistent tmp/pids/server.pid file. Learn to create and use a docker-entrypoint.sh script to automate cleaning this file before the server starts, ensuring reliable startup with Docker Compose.

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 ...