Create A Rails App With Docker
Step 1: Change to your home directory
WindowsType this in the terminal:cd c:\SitesMac or LinuxType this in the terminal:cd ~
Step 2: Create a railsbridge directory
Type this in the terminal:mkdir railsbridge
Step 3: Change to your new railsbridge directory
Type this in the terminal:cd railsbridge
Step 4: Create a new Rails app
Type this in the terminal:mkdir test_appType this in the terminal:cd test_appsource "https://rubygems.org" gem "rails", "5.2.0"Type this in the terminal:touch Gemfile.lockFROM ruby:2.5.1-slim RUN apt-get update -qq && apt-get install -y build-essential libpq-dev git vim nodejs postgresql-client build-essential ENV APP_HOME /test_app RUN mkdir -p $APP_HOME WORKDIR $APP_HOME COPY Gemfile* $APP_HOME/ RUN bundle install COPY . $APP_HOMEversion: '3' services: db: image: postgres:10.3 volumes: - db_data:/var/lib/postgresql/data web: build: . environment: DATABASE_URL: db tty: true stdin_open: true volumes: - .:/test_app command: bash -c 'rm -rf /test_app/tmp/pids/server.pid && bin/rails s -p 3000 -b 0.0.0.0' ports: - "3000:3000" depends_on: - db volumes: db_data: driver: local.git .dockerignore .byebug_history log/* tmp/* Dockerfile README.mdType this in the terminal:docker-compose run web rails new . --force --database=postgresqlType this in the terminal:docker-compose builddefault: &default adapter: postgresql encoding: unicode username: postgres password: pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> host: <%= ENV.fetch("DATABASE_URL") %> development: <<: *default database: test_app_development test: <<: *default database: test_app_test production: <<: *default database: test_app_production password: <%= ENV['APP_DATABASE_PASSWORD'] %>Type this in the terminal:docker-compose run web rails db:createType this in the terminal:docker-compose run web rails db:migrateType this in the terminal:docker-compose upType this in the terminal:docker-compose down
Step 5: Generate a database model
Type this in the terminal:docker-compose run web bashType this in the terminal:rails generate scaffold drink name:string temperature:integerType this in the terminal:rails db:migrateType this in the terminal:docker-compose upType this in the terminal:docker-compose down
Next Step:
Go on to Deploy A Rails App