DEV Community

Cover image for Fix docker rails error: tmp/pids/server.pid Not Cleaned Up
David
David

Posted on

Fix docker rails error: tmp/pids/server.pid Not Cleaned Up

If you work on a Rail app with Docker, you may encounter a docker rails error that says "A server is already running (pid: pid_number, file: /app/tmp/pids/server.pid)".
I was frustrated when that happened to me, so I decided to write this article and show you how I fixed it. It's pretty simple in reality. Let's go!

  • create a docker-entrypoint.sh file at the root of your project. This is what mine looks like
#!/bin/bash
set -e

if [ -f tmp/pids/server.pid ]; then
  rm tmp/pids/server.pid
fi

exec bundle exec "$@" 
Enter fullscreen mode Exit fullscreen mode
  • add this to your Dockerfile, just before starting your server

Start the Rails server

ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["rails", "server", "-b", "0.0.0.0"]

Run docker-compose up again and everything should be ok.

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more