-
Initialize your project folder with git:
git init -
Create (and commit) your project files with a temporary ruby image:
docker run -it -v .:/rails ruby:3.2.2 /bin/bash cd /rails gem install rails rails new . exit -
Copy the
Dockerfileinto a newDockerfile.dev- Remove any environment variables
- Modify
bundle installstep to only bundle install - Remove precompilation steps
- Test it with
docker build Dockerfile.dev .
-
Create a
docker-compose.yml:version: "3" services: app: build: context: . dockerfile: Dockerfile.dev command: ./bin/rails server -b 0.0.0.0 ports: - "3000:3000" volumes: - .:/rails -
Configure the rails web console to work in docker in
development.rb:# Allow IRB in browser for a docker environment config.web_console.permissions = '192.168.0.0/16' -
Migrating to postgres:
-
Setup docker service
version: "3" services: app: build: context: . dockerfile: Dockerfile.dev command: ./bin/rails server -b 0.0.0.0 environment: DATABASE_HOST: db DATABASE_PASSWORD: password ports: - "3000:3000" volumes: - .:/rails db: image: postgres:15 environment: POSTGRES_PASSWORD: password volumes: - db:/var/lib/postgresql/data volumes: db: -
Run
dbdocker service:docker compose up db -
bin/rails db:system:change --to=postgresql -
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
-
Last active
June 4, 2025 22:19
-
-
Save juanca/b627f87a98229f36b5e456d59299214f to your computer and use it in GitHub Desktop.
[GUIDE] Starting a new Ruby on Rails project in docker
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment