This repository serves as an educational docker template over which to build a rails app.
Special thanks to @daleal. Edited and updated by @dagalloso._
- Install Docker.
- Install docker-compose (for linux).
-
Copy files & change app name from
exampleonDockerfile,entrypoint.shanddocker-compose.ymlto your app's name. -
Create env file:
touch .env
-
Create a rails app:
docker-compose run web rails new . --force --no-deps --database=postgresql -
Build the Docker image:
docker-compose build
-
Get ownership of the files (on linux they are owned by root when created):
sudo chown -R $USER: .
-
Connect the database (replace the content of
config/database.ymlwith the following, change{example}with your app's name):default: &default adapter: postgresql encoding: unicode host: db username: postgres password: pool: 5 development: <<: *default database: {example}_development test: <<: *default database: {example}_test
-
Create the database:
docker-compose run web rails db:create
-
Run the app:
docker-compose up
-
Or without logs
docker-compose up -d
-
Build the Docker image:
docker-compose build
-
Start the server:
docker-compose up
-
Or without logs
docker-compose up -d
-
Stop the server:
docker-compose down
-
Run rails
command(command=rails ...):docker-compose run web `command` -
Get ownership of files created by rails generate (on linux they are owned by root when created):
sudo chown -R $USER:$USER .
Couldn't connect do Docker daemon. Fix: run the command again withsudoat the beginning (Linux problem).- Error when creating the database. Fix: run
docker-compose up,docker-compose downand run the command again.
If your coworker already created the app and you want to run the existing up:
- Clone the repo.
- Build the containers (
docker-compose build). - Create the database at your computer (
docker-compose run web rails db:create). - Run the app (
docker-compose up).