- Your machine runs a Debian-based Linux distribution (e.g., Ubuntu).
- You have Docker installed in your development or deployment machine.
cd $PATH_TO_PROJECT/twitter-rails-api/
# For example, cd ~/Code/twitter-rails-api/
docker-compose -f docker-compose.dev.yml build
docker-compose -f docker-compose.dev.yml up -d
Take note that the first occurrence of postgres
refers to the service name,
which is the name of the relevant service defined in our docker-compose.dev.yml
.
docker-compose -f docker-compose.dev.yml exec postgres-dev psql -U postgres
If you didn't set the TRA_DEV_USER_PASSWORD
recently, enter the following
SQL commands:
CREATE USER tra_user WITH PASSWORD 'password';
ALTER USER tra_user CREATEDB;
Say that you've set TRA_DEV_USER_PASSWORD
to nokia3310
. If so, enter the
following instead:
CREATE USER tra_user WITH PASSWORD 'nokia3310';
ALTER USER tra_user CREATEDB;
Quit the interactive terminal.
\q -- Quit the psql terminal
Executing the command below will "[create] all databases, loads all schemas,
and initializes with the seed data [defined in db/seeds.rb
]."
docker-compose -f docker-compose.dev.yml exec app-dev bundle exec rails db:setup
Run the following command:
docker-compose -f docker-compose.dev.yml exec app-dev \
bin/rails server -b 0.0.0.0
Now you can open your browser and go to http://localhost:3000
.
Unlike in the Dockerized production instance, there's not need to restart the containers upon changing the source code (for most situations). Just refresh your browser page.
If a simple page refresh won't cut it, try to run the following:
docker-compose -f docker-compose.dev.yml down
docker-compose -f docker-compose.dev.yml build
docker-compose -f docker-compose.dev.yml up -d
docker-compose -f docker-compose.dev.yml exec app-dev bin/rails db:migrate