Ruby Bundle Relies on Postgres (2 Separate Containers)

Hi all,

I’ve been trying to convert a monolithic app to a microservice architecture. The application requires the following:

  1. httpd
  2. redis
  3. passenger
  4. sidekiq
  5. postgres

The first 4, unfortunately, need to be run inside of a single container, as the application doesn’t currently have configuration settings to speak to an external redis.

But the Postgres service could (and should) be run externally to the primary application container. However, the problem I’m having is that bundle relies on having Postgres packages installed in its environment.

I’ve thought of using the --link parameter, but this doesn’t work due to the fact that bundle occurs while the application image is “building”.

Any thoughts on how to get around this? Or is the temporary solution (until their architecture allows otherwise) to just run Postgres inside of the application container…?

You can have everything within a single Dockerfile and have Postgres and the application run in two separate containers by having a command for the application and a command for Postgres.

docker run exampleimage bundle exec rails s
docker run exampleimage postgres pg_ctl -D "$PGDATA" -m fast -w stop

Hopefully that helps.