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.
[GUIDE] Starting a new Ruby on Rails project in docker
  1. Initialize your project folder with git: git init

  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
    
  3. Copy the Dockerfile into a new Dockerfile.dev

    1. Remove any "production", "precompile" instructions
    2. Test it with docker build Dockerfile.dev .
  4. 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
    
  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'
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment