Git Product home page Git Product logo

docker-compose-rails-startup's People

Contributors

deathbyjer avatar

Watchers

 avatar  avatar

docker-compose-rails-startup's Issues

Updated README

@deathbyjer I've updated the README with a few more steps as well as adding the instructions for setting up a test environment in case you wish to point people here in the future. I couldn't open a PR due to access restrictions. This should cover most places where I got stuck, but I may have missed a step or two. Later this week I'll try this again to ensure accuracy!

`Startup a Docker-Compose project with Rails

This is a quickly updated version of the startup portion from https://docs.docker.com/samples/rails/

Purpose

There has been confusion using the sample provided by docker-compose, so I resolved to provide an easy-to-use skeleton that can be quickly booted up.
The two main items I edited was bumping the Rails version to 6 and making the Dockerfile expecting the its directory to also be the Rails directory.

Steps

  1. Clone this repo
  2. Change folder name to the name of the app you wish to create.
  3. Within Dockerfile be sure to replace all instances of myapp with your intended application name.
  4. Run docker-compose run --no-deps web rails new . --force --database=postgresql within the directory. (This will setup Rails)
  5. Run docker-compose run --no-deps web chown -R 1000:1000 * (This will reset the permissioning on the generated files so you can work on them locally)
  6. Run docker-compose build web (This will ensure that everything is appropriate built off the Rails-generated Gemfile
  7. Run docker-compose up (to start the service!)
  8. While that is running hit cmd+t (on mac, ctrl+t on widowns) in terminal to open a new terminal tab.
  9. Within that tab run docker-compose run web rake db:create to create you docker db.

Be advised that some of these commands can take 3-7 minutes, depending on your system.

Testing Database Setup

If you wish to set up a database for docker as well as one for testing the following is recommended.
Again, making sure to replace myapp with your applications name!

  1. Change docker-compose.yml to the following.
version: "3.9"
services:
  db:
    image: postgres
    volumes:
      - ./tmp/db:/var/lib/postgresql/data
    environment:
      POSTGRES_PASSWORD: password
  web:
    build: .
    command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
    volumes:
      - .:/myapp
      - ./docker/database.yml:/myapp/config/database.yml #New directory for docker!
    ports:
      - "3000:3000"
    depends_on:
      - db

This will point docker towards one db and your tests towards another as to avoid any conflicts.

  1. In config/database.yml copy and paste the following.
default: &default
  adapter: postgresql
  encoding: unicode
  host: localhost # Local db for testing
  username: postgres
  password: password
  pool: 5

development:
  <<: *default
  database: myapp_development


test:
  <<: *default
  database: myapp_test
  1. Create your new docker folder in your main application directory and place the following database.yml.
default: &default
  adapter: postgresql
  encoding: unicode
  host: db #Local db for Docker
  username: postgres
  password: password
  pool: 5

development:
  <<: *default
  database: myapp_list_development


test:
  <<: *default
  database: myapp_list_test
  1. Rerun docker-compose up.
    `

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.