Skip to content

Creating Dockerfile

Create a new Rails app

Run

rails new rails70

Add dockerfile-rails to Gemfile

gem "dockerfile-rails", "~> 1.2.5", :group => :development

We will run docker on x86-64 linux on ECS, so we need to add platform support for x86-64

bundle lock --add-platform x86_64-linux

Run bundle install

Generate Dockerfile

dockerfile-rails is a Rails generator to produce Dockerfiles.

Run

bin/rails generate dockerfile

to generate a Dockerfile:

Info

This Dockerfile uses --link, so the syntax has to be at least 1.4 (line 1).

Info

dockerfile-rails supports many different parameters, I encourage you to check out its demo and the supported parameters.

Test Dockerfile on local

Info

You need to have Docker installed on your local

Add a default route to routes.rb

root "rails/welcome#index"

Run the following command

docker buildx build . -t rails70
docker run -p 3000:3000 -e RAILS_MASTER_KEY=$(cat config/master.key) --rm rails70

Open up your browser and go to localhost:3000 Screen Shot 2023-04-30 at 7 41 48 pm Contgratulations, you have successfully run Rails container on your local. Next we will deploy the same image to AWS.

Info

At this moment, we only have a Rails skeleton app, there is no caching layer (Redis) or persistence layer (Postgres). We will make sure the skeleton app runs ok on AWS, and then add those layers.