

Rails revolutionized web development by making it easy to make a small change in your application code, hit reload, and see your results immediately. My biggest issue when working with Docker and Rails And, we still can use it when working locally. Now, if we hit, we see the rails app running! Eureka, it works. So, we need both a CMD and an ENTRYPOINT command: CMD and ENTRYPOINT both work once the container is instantiated, but running CMD seems to override the existing ENTRYPOINT for the rails base image (which means it won’t run “rails s” to start the server). The “run” phase is the only time our app gets the environment variables for the postgres server. RUN is not going to work, because this runs a command which is built into the image: RUN happens at the “compile” phase, when the image is generated, not at the “run” phase. Be sure to notice the difference between the RUN, CMD and ENTRYPOINT, each of which looks like it could help. We can add this to our Dockerfile so that after our container is built we run this command. We now need to make sure to run the rails command “rake db:schema:load” to load our schema into the database right after we instantiate the container which is linked to Postgres. We have the host dynamically determined if running within Docker, and we specify the username based on whether we are running locally or inside Docker. Our local server does not care that what the name is, but our dockerized server does, so let’s use the one which works for Docker. Note that we changed the database to “postgres” from the original “ruby-rails-sample_development” name. eql?( "xrdawson" ) ? "xrdawson" : "postgres" % >
RUBY RUNNER HEROKU CODE
Unfortunately, using the installation instructions for nsenter did not work (it never built the binary into my OSX /usr/local/bin directory) but putting this snippet of code (explained further down in the README) did work. This is the right way to debug running containers as you keep your experimental commands out of the workflow for building the final image. Instead we can use nsenter from one of the Docker employees to shell into a running container.
RUBY RUNNER HEROKU INSTALL
You could install SSH temporarily, but then we are cluttering the image and our build steps will get complicated when we back out the change to ready for deployment. But, we can’t get SSH into our container: for the same reasons that we don’t want to run postgres inside the same container as our Rails app, it is consensus among many Docker users that we should not use an SSH server inside our container, and I generally agree. A better way to troubleshoot is to inspect our container itself. But, since our rails app is running inside a new context, namely a Docker container, our results are limited right now. When things don’t work, we could of course do a Google search.
RUBY RUNNER HEROKU HOW TO
What to do? And, how to do it keeping it working on Heroku and running locally? Troubleshooting using nsenter Our app is not properly configured to reach the postgres linked server, so the error message is the same.


Start with the sample application from Heroku ( ) If you need more details on a specific step, just jump back to the section where that step is explained in more detail.

This section gives you a quick how to when enabling your rails app for Docker. If you are busy, you can skip to the TL DR section at the very end of this post to see how I took an app which runs on Heroku and converted it to running inside Docker as a multiple process set of containers. Understanding how these components link together and (troubleshooting them when they don’t) is something I wish I had known before playing with Docker and Rails. But, when you start running apps which use Heroku services (even the Postgres database is a service to your app), things get complicated because you need to link containers, and there is sadly little information on the Internet (the Docker docs are very generic) about how to do this. Specifically, there is very little step-by-step information about how to link an app in a real application framework with a real database service. Running a single process container (like a Rails app using Sqlite) is simple. I’ve hit a few snags as I’ve been experimenting and wanted to share my experiences and how I overcame a few gotchas. I’ve been experimenting with migrating applications currently hosted on Heroku to Docker.
