- Download the project first or git clone.
git clone https://github.com/Mashpy/rails-7-docker-template-with-postgresql.git
If you clone you have to change your repo name later from .git/config file
- Rename the project name as your wish
mv rails-7-docker-template-with-postgresql your_project_name
- Change directory -
cd your_project_name
- Update your rails version on the Gemfile -
source 'https://rubygems.org'
gem 'rails', '7.0.3'
- Update Ruby version on Dockerfile -
FROM ruby:3.1.2-slim
- Now install new rails app -
docker-compose run app rails new . --force --database=postgresql --skip-bundle
- Build the docker image -
docker-compose build
- Update database details on config/database.yml file.
default: &default
adapter: postgresql
encoding: unicode
host: postgres
username: postgres
password: password
pool: 5
development:
<<: *default
database: dev
test:
<<: *default
database: dev
- Run -
docker-compose up
- wait little bit see your eyes on the console, it should show -
Puma Listening on http://0.0.0.0:3000
Pg admin Listening at: http://[::]:80 (1)
It will take time to load. Keep patient. After then then open another terminal and create a database -
docker-compose exec app rake db:create
-
Browse http://localhost:3000.
-
Browse http://localhost:5050/ . You can login on pgadmin. username: admin@admin.com password: password
-
Add database connection on pgadmin. You need your postgres_container IP address.
docker ps
copy hash code of postgres_container.
docker inspect fcc97e066cc8 | grep IPAddress
-
after login on pgadmin add connection. Write host IP address. username: postgres password: password
-
now you can start work on your project.
