Logo

dev-resources.site

for different kinds of informations.

Docker in development: Episode 3

Published at
1/9/2025
Categories
python
ruby
rails
webdev
Author
sinaptia_dev
Categories
4 categories in total
python
open
ruby
open
rails
open
webdev
open
Author
12 person written this
sinaptia_dev
open
Docker in development: Episode 3

The last episode was about dockerizing our Ruby on Rails app. In this episode, we’ll be exploring how to perform everyday tasks in our containers.

Running rake tasks and rails commands
Running rake tasks is easy. Once you’ve built your images, you can use docker-compose to run commands in them. For example, if you want to see the routes of your app:

$ docker-compose run web rails routes
Similarly, if you want to create the db, migrate, and seed:

$ docker-compose run web rails db:create db:migrate db:seed
If, instead, you want to run your test suite, you’ll have to create the test db:

$ docker-compose run web rails db:create db:migrate RAILS_ENV=test
and then run the test suite (assuming rake defaults to rake test):

$ docker-compose run web rake
Tip: create your custom scripts/aliases
I’ve run docker-compose run web rails ... a hundred times a day, so to make things easier I put this script in my $PATH:

!/bin/bash

docker-compose run web rails "$@"
Note that this script assumes your docker-compose.yml file has a web service. If you don’t, it won’t work.

Performing other tasks
So far, all commands are quite straightforward, you just run them within the web service. What happens with somewhat harder tasks such as loading a pre-existing database into your container’s database? This is one of the tasks that took me longer to figure out.

In postgres, there are 2 ways of doing this and it depends on the dump’s format. In the past we had to deal with --format=c dumps and regular dumps.

Assuming you have a latest.dump file that contains a postgres dump in c format, and you want to load it in your (running) container, you first have to figure out what your container id is. You can do that by running:

$ docker container ls
or

$ docker ps
Once you have the container id (in this example we’ll use 80f8041db4b4), you can run this command to restore the dump in the container:

$ docker exec -i 80f8041db4b4 pg_restore -d app_development -U postgres < latest.dump
If instead, you have a regular dump (eg. latest.sql), you can run this command to restore it:

$ docker exec -i 80f8041db4b4 psql -d app_development -U postgres < latest.sql
If you’re using docker-compose, things get easier:

$ docker-compose exec -T db pg_restore -d app_development -U postgres < latest.dump
Dockerize everything!
I use elastic beanstalk a lot. I usually install it with Homebrew, but it installs a bunch of dependencies of its own, like Python, SQLite, etc. I don’t want all of that in my system, especially because I always have trouble with Python versions. Instead, I dockerized it: docker-awsebcli.

Join us in the next episode!

ruby Article's
30 articles in total
Favicon
Ruby on Rails 8 API not allowing mobile phone connection
Favicon
ruby -run
Favicon
ruby -run, again
Favicon
Ruby on Rails: Your Service Layer is a Lie
Favicon
Die Ruby-Seite von Puppet - Teil 2 - Benutzerdefinierte Funktionen
Favicon
The Ruby side of Puppet - Part 2 - Custom Functions
Favicon
Introducing Ephem
Favicon
What Is It (in Ruby 3.4)?
Favicon
Unable to find Ruby class that definitely exists
Favicon
Devise not accepting JSON Token
Favicon
Ruby on Rails - Calculating pricing based user's purchasing power parity
Favicon
Ruby on Rails 8 - Frontend Rápido Usando Tailwind como um Frameworks CSS Classless
Favicon
Use cases for Turbo's Custom Events
Favicon
Meta programming with Ruby Eval: A guide (Part 1)
Favicon
Tracing a method call in Ruby
Favicon
False positives of Lint/Void in assignments
Favicon
Die Ruby-Seite von Puppet - Teil 1 - Benutzerdefinierte Fakten
Favicon
Just committed to learning ruby for sonic pi and rails https://dev.to/highcenburg/2025-roadmap-mastering-ruby-for-sonic-pi-and-rails-696 wish me luck!
Favicon
Building a GitHub Activity CLI - A Ruby Journey
Favicon
I have been thinking of moving forward from Python to Ruby to align my skills with my musicality since I like to learn SonicPi.. But I'm still thinking about it so yeah
Favicon
Task Tracker CLI
Favicon
Rails 8 CRUD: Modern Development Guide 2025
Favicon
When Controllers Take on Too Much Responsibility
Favicon
Ruby on Rails 8 - Frontend Rápido com Frameworks CSS Classless ou Class-Light sem CDN
Favicon
Cdg Hoodie or Eric Emanuel Hoodie: The Trend You Need Now
Favicon
Brakeman LSP Support
Favicon
Docker in development: Episode 3
Favicon
Add Invite to Rails 8 Authentication
Favicon
How to Develop an Air Quality Monitoring App with Ruby on Rails
Favicon
School

Featured ones: