nickjj / docker-rails-example

A production ready example Rails app that's using Docker and Docker Compose.
MIT License
941 stars 185 forks source link

Steps to Integrate with existing app #65

Open crslade opened 10 months ago

crslade commented 10 months ago

I have an existing app. Is there some sort of checklist on what you have to do to integrate this into an existing app? I tried several times to integrate it with my app but haven't had success in getting it working.

The web container fails, saying that an existing server already exists. I have tried adding in a line in the entrypoint script to remove the /app/tmp/pids/server.pid file. Any suggestions on this?

Finally are there any other concerns I need to worry about running this on a M1 Mac? Do I need docker_sync to make it run better?

Thanks!

nickjj commented 10 months ago

Hi,

Everything should work with Apple Silicon. Modern versions of Docker Desktop with VirtioFS on macOS has good volume mount performance without docker_sync.

The README file has a list of changes vs a newly generated Rails at: https://github.com/nickjj/docker-rails-example#main-changes-vs-a-newly-generated-rails-app

Manually deleting the server.pid file is sometimes a step to perform if puma crashes hard without being able to clean itself up or you had an existing file prior to using Docker.

https://nickjanetakis.com/blog/a-guide-for-running-rails-in-docker covers a bunch of assorted topics.

crslade commented 10 months ago

Thanks. I was following along with your video and guide and didn't see the readme. That is very helpful.

Sorry if this shows my misunderstanding of docker, but the tmp directory (where the pid is stored) is in the .dockerignore file. So, the pid isn't coming from the host machine. It must be coming from the web container (or maybe the cable container?). How would I delete the pid file in the container, since it quits when puma can't start? I tried with the entrypoint script, and I tried tacking it onto the CMD in the dockerfile: CMD ["rm -f /app/tmp/pids/server.pid && rails s ...."]. Neither way worked.

Thanks again, this is a great guide.

nickjj commented 10 months ago

Under normal scenarios that pid file won't exist after puma stops. normally puma will delete it during its shutdown phase.

But deleting this file in an ENTRYPOINT script is not a bad idea, this will run before puma is started which will ensure no pid file exists before puma starts.

crslade commented 10 months ago

What do you think about this for stale pids? https://ieftimov.com/posts/docker-compose-stray-pids-rails-beyond/

nickjj commented 10 months ago

I'd prefer to have it in the entrypoint script since that gets executed before puma starts, it's basically the same as the CMD approach but a little cleaner. Alternatively configuring puma not to write a pid could be an option (I never looked into this to see if this is a good or bad idea).