hoangdangninh
4/26/2017 - 5:11 AM

steps to configure postgres database for dev and test using rails, docker

steps to configure postgres database for dev and test using rails, docker

### STEPS TO CONFIGURE POSTGRES DATABASE FOR DEV AND TEST ###
### USING RAILS, DOCKER ................................. ###

0) Check if you have postgres image from dockerhub, if not pull it
> docker images
> docker pull postgres
 
1) Find out what db container is running in docker:
> docker ps

2) Stop it
> docker stop <container-name>

3) Kill it
> docker rm <container-name>

4) Make sure no postgres service is running natively:
> service --status-all | grep postgres
> service stop postgres

5) Recreate that container using same username for 
   DEV and TEST and PROD, no password. Refer to database.yml file
> docker run --name <container-name> -p 5432:5432 -e POSTGRES_USER=<username-in-database.yml> postgres

6) Test if you can connect to DBMS by using psql command
> psql -h localhost -U <username-in-database.yml>

7) List all databases available, there should not be the database in database.yml file
=# \l

8) Create a database for DEV and TEST, respectively specified in database.yml
>  rake db:create

9) Migrate a database, ie: put table in it
> rake db:migrate

10) Run rails server based on environment, ie
> rails server -e development
or
> rails server -e test

11) Test the site through browser