In order to kickstart the application we need to install the rails gem and run the rails new <appname> command. We will do this inside the same Docker container that will be used to run the application itself. To do so we need to create a Dockerfile to create the Docker image with the necessary dependencies, a docker-compose.yml file to provision the other services needed (a postgres database and a volume store) and a Gemfile (with an empty Gemfile.lock) to install the rails gem and bundle install its dependencies.
Create a new directory and some empty files:
Copy and paste the following content in the respective files:
File Dockerfile
File docker-compose.yml
File Gemfile
Build the project
First we need to bundle the rails 5 dependencies:
And then use the rails new command to create the new application:
Configure the database
We need to change slightly the database configuration to use the environment
variables set in the docker-compose file:
File: config/database.yml
Setup the app
Create a start.sh file in the bin dir:
File: bin/start.sh
It automatically removes the server.pid that will create problems when you stop
and restart the app.
Make the file executable with the chmod command:
Finally start your newly created Rails application and visit localhost:3000: