-
Initialize your project folder:
git init
-
Create your project files with a ruby image:
docker run -it -v .:/rails/<app_name> -w /rails/<app_name> ruby:latest /bin/bash gem install rails rails new . exit
-
Configure the rails web console to work in docker in
development.rb
:# Allow IRB in browser for a docker environment config.web_console.permissions = '0.0.0.0/0'
-
Create a
docker-compose.yml
:services: app: image: ruby:<version from gemfile> command: ./bin/rails server -b 0.0.0.0 ports: - "3000:3000" volumes: - .:/rails/<app_name> - bundle:/usr/local/bundle working_dir: /rails/<app_name> volumes: bundle:
-
Setup the application:
docker compose run app bin/setup
-
Start the application:
docker compose up
-
Copy the
Dockerfile
into a newDockerfile.dev
- Remove any environment variables
- Modify
bundle install
step to only bundle install - Remove precompilation steps
- Test it with
docker build Dockerfile.dev .
-
Create a
docker-compose.yml
:services: app: build: context: . dockerfile: Dockerfile.dev command: ./bin/rails server -b 0.0.0.0 ports: - "3000:3000" volumes: - .:/rails
-
Setup docker service:
services: app: # ... environment: DATABASE_HOST: db DATABASE_PASSWORD: password # ... db: image: postgres:15 environment: POSTGRES_PASSWORD: password volumes: - db:/var/lib/postgresql/data volumes: db:
-
Run
db
docker service:docker compose up db
-
docker compose run app bin/rails db:system:change --to=postgresql
-
docker compose run app bin/setup
-
Modify
./config/database.yml
:default: &default adapter: postgresql encoding: unicode host: <%= ENV["DATABASE_HOST"] %> password: <%= ENV["DATABASE_PASSWORD"] %> # For details on connection pooling, see Rails configuration guide # https://guides.rubyonrails.org/configuring.html#database-pooling pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> username: postgres
-
Setup docker volume:
services: app: # ... volumes: # ... - fly:/root/.fly # ... volumes: fly:
-
docker compose run app /bin/bash
-
curl -L https://fly.io/install.sh | sh
-
/root/.fly/bin/fly auth login
-
/root/.fly/bin/fly launch
NOTE: Use Web UI to confirm settings! -
After which you can just deploy:
docker compose run app /root/.fly/bin/fly deploy