Update docker-entrypoint template to avoid failing container restarts #50628
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation / Background
Rails provides great templates for running applications with Docker. However, when running Rails apps with the default
docker-entrypoint
, containers may fail to restart if they crashed (e.g. because of OOM). This is becuase the/rails/tmp/pids/server.pid
file is already present.Such failed containers will require manual intervention (e.g. remove the faulty container) to get up-and-running again. To allow containers to restart the server.pid file must be removed on container start.
This Pull Request has been created to incorporate this improvement into the default
docker-entrypoint
template.Detail
This Pull Request changes the
docker-entrypoint
template used when generating a new Rails application. A new line to remove any existing server PID files has been added.The
-f
flag is required to avoid failing the command if the file is not present (as should be the case for any new container).Additional information
The abovementioned issue can be reproduced by running a Rails application container, killing it, and trying to start the same container again. I'd be happy to create a separate bug report if additional details or reproduction steps are required.
There is no alternative solution that I know of. I can't think of any side effects caused by removing the server.pid file if its present either. After all, containers are supposed to be ephermal, and the file should actually never be there in the first place.
The fix proposed in this PR is commonplace see for example GitHub discussion or the Entrypoint for httpd default image.