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 "$@"
- 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)