Loading...

Blog

Latest blog posts

dcrails: execute Rails commands inside Docker

The problem

In Trito we use Docker to develop Ruby on Rails applications.

Rails has many commands that are called from the console like

rails g model MyModel
rails db:migrate
rails c

However, when we started using Docker all this become a bit more tedious

docker compose up app rails g model MyModel
docker compose up app rails db:migrate
docker compose up app rails c

The solution

To fix this we created the following script named dcrails (from docker-compose rails):

docker-compose run --rm app rails $*

Just create a file named dcrails with the previous command, add execution permisions to it (chmod +x dcrails), and place it on a path on a folder in the $PATH.

Now we just need to use:

dcrails g model MyModel
dcrails db:migrate
dcrails c

That's all folks!