A simple rails api to demonstrate Service Oriented Architecture.
- Ruby 2.4
- Rails 5.1.4
- Postgresql 10.0
- Docker & Docker Compose
- Follow the instructions to install Docker and Docker Compose.
- Once docker is installed, run
docker-compose up --build
The application is now running at localhost:3000
- Create and migrate the database.
docker-compose exec api rake db:create
docker-compose exec api rake db:migrate
- To stop the application, go to your terminal where you are running the docker containers and press
CTRL+C
. - To stop the services, run
docker-compose stop
. - To stop the containers, run
docker-compose down
.
Once you have created your images, you can use docker-compose up
to start the containers. Some helpful commands:
docker-compose ps
: List containersdocker-compose start
: Start servicesdocker-compose stop
: Stop servicesdocker-compose exec
: Execute a command on a containerdocker-compose run
: Execute a one-off command on a container
Please refer to docker-compose help
for all commands.
Developing a Rails application on a docker container is not so different from development in a local environment. You should be able to run all commands as you normally would, but you must prefix them with docker-compose exec ${name of container}
. The containers are named as so:
api
- Rails servicedb
- Postgres database
For example, running bundle install on the Rails service looks like:
docker-compose exec api bundle install
See the docker-compose.yml
in the root of the project for configuration.
docker-compose exec api rspec