Skip to content

Instantly share code, notes, and snippets.

@juanca
Last active June 4, 2025 22:19
Show Gist options
  • Select an option

  • Save juanca/b627f87a98229f36b5e456d59299214f to your computer and use it in GitHub Desktop.

Select an option

Save juanca/b627f87a98229f36b5e456d59299214f to your computer and use it in GitHub Desktop.

Revisions

  1. juanca revised this gist Dec 26, 2024. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions rails.md
    Original file line number Diff line number Diff line change
    @@ -3,8 +3,7 @@
    1. Initialize your project folder: `git init`
    2. Create your project files with a ruby image:

    docker run -it -v .:/rails/<app_name> ruby:latest /bin/bash
    cd /rails/<app_name>
    docker run -it -v .:/rails/<app_name> -w /rails/<app_name> ruby:latest /bin/bash
    gem install rails
    rails new .
    exit
  2. juanca revised this gist Aug 3, 2024. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion rails.md
    Original file line number Diff line number Diff line change
    @@ -108,4 +108,5 @@
    2. `docker compose run app /bin/bash`
    3. `curl -L https://fly.io/install.sh | sh`
    4. `/root/.fly/bin/fly auth login`
    5. `/root/.fly/bin/fly launch` NOTE: Use Web UI to confirm settings!
    5. `/root/.fly/bin/fly launch` NOTE: Use Web UI to confirm settings!
    6. After which you can just deploy: `docker compose run app /root/.fly/bin/fly deploy`
  3. juanca revised this gist Aug 3, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion rails.md
    Original file line number Diff line number Diff line change
    @@ -108,4 +108,4 @@
    2. `docker compose run app /bin/bash`
    3. `curl -L https://fly.io/install.sh | sh`
    4. `/root/.fly/bin/fly auth login`
    5. `/root/.fly/bin/fly auth launch` NOTE: Use Web UI to confirm settings!
    5. `/root/.fly/bin/fly launch` NOTE: Use Web UI to confirm settings!
  4. juanca revised this gist Aug 3, 2024. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions rails.md
    Original file line number Diff line number Diff line change
    @@ -105,6 +105,7 @@
    volumes:
    fly:
    2. Install flyctl: `docker compose run app /bin/bash` then `curl -L https://fly.io/install.sh | sh`
    3. `/root/.fly/bin/fly auth login`
    4. `/root/.fly/bin/fly auth launch` NOTE: Use Web UI to confirm settings!
    2. `docker compose run app /bin/bash`
    3. `curl -L https://fly.io/install.sh | sh`
    4. `/root/.fly/bin/fly auth login`
    5. `/root/.fly/bin/fly auth launch` NOTE: Use Web UI to confirm settings!
  5. juanca revised this gist Aug 3, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion rails.md
    Original file line number Diff line number Diff line change
    @@ -105,6 +105,6 @@
    volumes:
    fly:
    2. Install flyctl: `...`
    2. Install flyctl: `docker compose run app /bin/bash` then `curl -L https://fly.io/install.sh | sh`
    3. `/root/.fly/bin/fly auth login`
    4. `/root/.fly/bin/fly auth launch` NOTE: Use Web UI to confirm settings!
  6. juanca revised this gist Aug 3, 2024. 1 changed file with 4 additions and 6 deletions.
    10 changes: 4 additions & 6 deletions rails.md
    Original file line number Diff line number Diff line change
    @@ -45,23 +45,21 @@

    1. 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
    ports:
    - "3000:3000"
    volumes:
    - .:/rails

    ## Postgres

    1. Setup docker service:

    version: "3"
    services:
    app:
    # ...
  7. juanca revised this gist Aug 3, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion rails.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    ## Bootstrap project

    1. Initialize your project folder with git: `git init` and create `.gitignore`
    1. Initialize your project folder: `git init`
    2. Create your project files with a ruby image:

    docker run -it -v .:/rails/<app_name> ruby:latest /bin/bash
  8. juanca revised this gist Aug 3, 2024. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions rails.md
    Original file line number Diff line number Diff line change
    @@ -33,6 +33,8 @@

    2. Setup the application: `docker compose run app bin/setup`

    3. Start the application: `docker compose up`

    ## Advanced environment

    1. Copy the `Dockerfile` into a new `Dockerfile.dev`
  9. juanca revised this gist Aug 3, 2024. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions rails.md
    Original file line number Diff line number Diff line change
    @@ -31,6 +31,8 @@
    volumes:
    bundle:

    2. Setup the application: `docker compose run app bin/setup`

    ## Advanced environment

    1. Copy the `Dockerfile` into a new `Dockerfile.dev`
  10. juanca revised this gist Aug 3, 2024. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions rails.md
    Original file line number Diff line number Diff line change
    @@ -22,12 +22,12 @@
    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>
    ports:
    - "3000:3000"
    volumes:
    - .:/rails/<app_name>
    - bundle:/usr/local/bundle
    working_dir: /rails/<app_name>
    volumes:
    bundle:

  11. juanca revised this gist Aug 3, 2024. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion rails.md
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,6 @@

    1. Create a `docker-compose.yml`:

    version: "3"
    services:
    app:
    image: ruby:<version from gemfile>
  12. juanca revised this gist Aug 3, 2024. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions rails.md
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    1. Initialize your project folder with git: `git init` and create `.gitignore`
    2. Create your project files with a ruby image:

    docker run -it -v .:/rails/<app_name> ruby:3.2.2 /bin/bash
    docker run -it -v .:/rails/<app_name> ruby:latest /bin/bash
    cd /rails/<app_name>
    gem install rails
    rails new .
    @@ -21,7 +21,7 @@
    version: "3"
    services:
    app:
    image: ruby:3.2.2
    image: ruby:<version from gemfile>
    command: ./bin/rails server -b 0.0.0.0
    ports:
    - "3000:3000"
  13. juanca renamed this gist Aug 3, 2024. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  14. juanca revised this gist May 20, 2024. 1 changed file with 20 additions and 2 deletions.
    22 changes: 20 additions & 2 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -56,7 +56,7 @@

    ## Postgres

    1. Setup docker service
    1. Setup docker service:

    version: "3"
    services:
    @@ -88,4 +88,22 @@
    # 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
    username: postgres
    ## Fly.io (WIP)

    1. Setup docker volume:

    services:
    app:
    # ...
    volumes:
    # ...
    - fly:/root/.fly
    # ...
    volumes:
    fly:
    2. Install flyctl: `...`
    3. `/root/.fly/bin/fly auth login`
    4. `/root/.fly/bin/fly auth launch` NOTE: Use Web UI to confirm settings!
  15. juanca revised this gist May 20, 2024. 1 changed file with 9 additions and 9 deletions.
    18 changes: 9 additions & 9 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -80,12 +80,12 @@
    5. `docker compose run app bin/setup`
    6. 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
    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
  16. juanca revised this gist May 20, 2024. 1 changed file with 16 additions and 16 deletions.
    32 changes: 16 additions & 16 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -58,22 +58,22 @@

    1. Setup docker service

    version: "3"
    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:
    version: "3"
    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:

    3. Run `db` docker service: `docker compose up db`
    4. `docker compose run app bin/rails db:system:change --to=postgresql`
  17. juanca revised this gist May 20, 2024. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -76,8 +76,9 @@
    db:

    3. Run `db` docker service: `docker compose up db`
    4. `bin/rails db:system:change --to=postgresql`
    5. Modify `./config/database.yml`:
    4. `docker compose run app bin/rails db:system:change --to=postgresql`
    5. `docker compose run app bin/setup`
    6. Modify `./config/database.yml`:

    default: &default
    adapter: postgresql
  18. juanca revised this gist May 20, 2024. 1 changed file with 5 additions and 7 deletions.
    12 changes: 5 additions & 7 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -9,6 +9,11 @@
    rails new .
    exit

    3. 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'

    ## Simple environment

    1. Create a `docker-compose.yml`:
    @@ -49,13 +54,6 @@
    volumes:
    - .:/rails

    ## Additional docker-specific configuration

    1. 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'

    ## Postgres

    1. Setup docker service
  19. juanca revised this gist May 20, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    ## Bootstrap project

    1. Initialize your project folder with git: `git init` and create `.gitignore`
    2. Create your project files with a temporary ruby image:
    2. Create your project files with a ruby image:

    docker run -it -v .:/rails/<app_name> ruby:3.2.2 /bin/bash
    cd /rails/<app_name>
  20. juanca revised this gist May 20, 2024. 1 changed file with 41 additions and 22 deletions.
    63 changes: 41 additions & 22 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -1,19 +1,41 @@
    1. Initialize your project folder with git: `git init`
    2. Create (and commit) your project files with a temporary ruby image:
    ## Bootstrap project

    docker run -it -v .:/rails ruby:3.2.2 /bin/bash
    cd /rails
    1. Initialize your project folder with git: `git init` and create `.gitignore`
    2. Create your project files with a temporary ruby image:

    docker run -it -v .:/rails/<app_name> ruby:3.2.2 /bin/bash
    cd /rails/<app_name>
    gem install rails
    rails new .
    exit

    3. Copy the `Dockerfile` into a new `Dockerfile.dev`
    ## Simple environment

    1. Create a `docker-compose.yml`:

    version: "3"
    services:
    app:
    image: ruby:3.2.2
    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:

    ## Advanced environment

    1. Copy the `Dockerfile` into a new `Dockerfile.dev`
    1. Remove any environment variables
    2. Modify `bundle install` step to _only_ bundle install
    3. Remove precompilation steps
    4. Test it with `docker build Dockerfile.dev .`

    4. Create a `docker-compose.yml`:
    1. Create a `docker-compose.yml`:

    version: "3"
    services:
    @@ -27,28 +49,25 @@
    volumes:
    - .:/rails

    5. Configure the rails web console to work in docker in `development.rb`:
    ## Additional docker-specific configuration

    1. 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'
    6. Migrating to postgres:
    1. Setup docker service
    config.web_console.permissions = '0.0.0.0/0'

    ## Postgres

    1. 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:
    @@ -58,9 +77,9 @@
    volumes:
    db:

    3. Run `db` docker service: `docker compose up db`
    4. `bin/rails db:system:change --to=postgresql`
    5. Modify `./config/database.yml`:
    3. Run `db` docker service: `docker compose up db`
    4. `bin/rails db:system:change --to=postgresql`
    5. Modify `./config/database.yml`:

    default: &default
    adapter: postgresql
  21. juanca revised this gist Mar 14, 2024. 1 changed file with 41 additions and 1 deletion.
    42 changes: 41 additions & 1 deletion gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -30,4 +30,44 @@
    5. 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'
    config.web_console.permissions = '192.168.0.0/16'
    6. Migrating to postgres:
    1. 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:

    3. Run `db` docker service: `docker compose up db`
    4. `bin/rails db:system:change --to=postgresql`
    5. 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
  22. juanca revised this gist Mar 11, 2024. 1 changed file with 11 additions and 8 deletions.
    19 changes: 11 additions & 8 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -1,19 +1,22 @@
    1. Initialize your project folder with git: `git init`
    1. Create (and commit) your project files with a temporary ruby image:
    2. 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

    1. Copy the `Dockerfile` into a new `Dockerfile.dev`
    1. Remove any "production", "precompile" instructions
    1. Test it with `docker build Dockerfile.dev .`
    1. Create a `docker-compose.yml`:
    3. Copy the `Dockerfile` into a new `Dockerfile.dev`
    1. Remove any environment variables
    2. Modify `bundle install` step to _only_ bundle install
    3. Remove precompilation steps
    4. Test it with `docker build Dockerfile.dev .`

    version: "3"
    services:
    4. Create a `docker-compose.yml`:

    version: "3"
    services:
    app:
    build:
    context: .
    @@ -24,7 +27,7 @@
    volumes:
    - .:/rails

    1. Configure the rails web console to work in docker in `development.rb`:
    5. 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'
  23. juanca revised this gist Mar 11, 2024. 1 changed file with 21 additions and 16 deletions.
    37 changes: 21 additions & 16 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -1,25 +1,30 @@
    1. Initialize your project folder with git: `git init`
    1. 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

    1. Copy the `Dockerfile` into a new `Dockerfile.dev`
    1. Remove any "production", "precompile" instructions
    1. Test it with `docker build Dockerfile.dev .`
    1. Remove any "production", "precompile" instructions
    1. Test it with `docker build Dockerfile.dev .`
    1. 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
    1. 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'

    version: "3"
    services:
    app:
    build:
    context: .
    dockerfile: Dockerfile.dev
    command: ./bin/rails server -b 0.0.0.0
    ports:
    - "3000:3000"
    volumes:
    - .:/rails

    1. 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'
  24. juanca renamed this gist Mar 11, 2024. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions gistfile1.txt → gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,14 @@
    1. Initialize your project folder with git: `git init`
    1. 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
    docker run -it -v .:/rails ruby:3.2.2 /bin/bash
    cd /rails
    gem install rails
    rails new .
    exit
    1. Copy the `Dockerfile` into a new `Dockerfile.dev`
    1. Remove any "production", "precompile" instructions
    1. Test it with `docker build Dockerfile.dev .`
    1. Create a `docker-compose.yml`
    1. Create a `docker-compose.yml`:
    version: "3"
    services:
    app:
  25. juanca created this gist Mar 11, 2024.
    25 changes: 25 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    1. Initialize your project folder with git: `git init`
    1. 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
    1. Copy the `Dockerfile` into a new `Dockerfile.dev`
    1. Remove any "production", "precompile" instructions
    1. Test it with `docker build Dockerfile.dev .`
    1. 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
    1. 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'