Giter Club home page Giter Club logo

simplest-rails-docker's Introduction

Simplest possible Rails 6 + docker-compose project

This repository is intended to be the simplest possible Rails 6 + docker-compose demo.

It builds and runs a simple "hello" page locally.

Rails, Database and Webpacker are the 3 mandatory services to get things works.

Steps to reproduce

0. Prerequisites

$> docker -v
Docker version 17.12.0-ce

$> docker-compose -v
docker-compose version 1.18.0

Any upper version should work.

1. Build images

Run :

docker-compose build

2. Build project

Run :

docker-compose run --rm --no-deps web-srv rails new . --skip --database=postgresql

This will run the rails new command on our web-srv service defined in docker-compose.yml.

Flag explanations:

  • --no-deps - Tells docker-compose run not to start any of the services in depends_on.
  • --skip - Tells rails NOT to overwrite existing files, such as README or .gitignore
  • --database=postgresql - Tells Rails to default our db config to use postgres.
  • --rm - Removes container after run

3. Adapt database.yml and webpacker.yml to Docker configuration

Open and change config/database.yml

default: &default
  host: db-srv # <---- add this property
  username: myuser # <---- add this property

4. Create hello world page

Run :

docker-compose run --rm --no-deps web-srv rails generate controller hello say_hello

Flag explanations:

  • --no-deps - Tells docker-compose run not to start any of the services in depends_on.
  • --rm - Removes container after run

5. Start services

docker-compose up

6. Visit "hello world" page

go to http://localhost:3000/hello/say_hello

  • Open the browser console to check that CSS, JS loaded correctly and no 404 request occured.
  • Check also the logs of the services in your terminal to notice that no error occured.

Restart from scratch

removes all docker containers, images, and volumes. Warning, all data will be lost.

docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
docker rmi $(docker images -q) -f
docker volume prune -f

remove all files generated by the "rails new" command

rm -rf -v !("Dockerfile"|".dockerenv"|".gitignore"|"README.md"|"docker-compose.yml") && rm .browserslistrc && rm .ruby-version

simplest-rails-docker's People

Contributors

bdavidxyz avatar

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.