Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using docker with RDS (Prod), but confused about local DB setup (dev)

I'm designing a Rails webapp using Docker and for a variety of reasons, I'd like to use RDS in the Production environment for its configurability & durability purposes, rather than a Docker container-based DB (this is a requirement).

I realize that I can configure database.yml to point to my RDS instance for Prod env, and to some local DB instance in my local dev env.

However, I'm confused as to whether to use a container-based DB in my local dev environment, or an external one like MySQL Server.

Based on the Docker pattern of env-agnostic containers, I suppose that having a container-based DB in only some envs wouldn't make any sense (in fact, I don't think docker-compose.yml would even support something like this), so I am assuming I'll need to go with the MySQL Server solution for my local dev env.

Has anybody else been through such a requirement? Let me know if I am thinking about this the right way. Also, would this pose any potential issues for DB migration scripts?

Any suggestions are welcome!

Thank you.

like image 856
Donald Avatar asked Jun 02 '17 18:06

Donald


1 Answers

Great questions Donald.

I have a postgres container set up for use locally using my dev.docker-compose.yml file.

And on prod, like you do, I have my database.yml configuration pointing to my RDS database.

On my prod docker compose file, I do not have any database container specified since I am using RDS

# prod.docker-compose.yml
version: "3.9"

services:
  web:
    build:
      context: .
      target: prod
      args:
        PG_MAJOR: '13'
        RUBY_VERSION: '2.6.6'
        BUNDLER_VERSION: '2.1.4'
    env_file: .env
    stdin_open: true
    tty: true
    command: ./bin/start_dev_server
    image: ${REGISTRY_HOST}
    ports:
      - "3000:3000"

# dev.docker-compose.yml
version: "3.9"

services:
  web:
    build:
      context: .
      target: dev
      args:
        PG_MAJOR: '13'
        RUBY_VERSION: '2.6.6'
        BUNDLER_VERSION: '2.1.4'
    env_file: .env
    stdin_open: true
    tty: true
    command: ./bin/start_dev_server
    volumes:
      - ".:/sokoplace"¬
      - bundle:/bundle
    ports:
      - "3000:3000"

  postgres:
    image: "postgres:13-alpine"
    volumes:
      - postgres:/var/lib/postgresql/data
    ports:
      - "5432:5432"
    environment:
      POSTGRES_HOST_AUTH_METHOD: trust

volumes:
  bundle:
  postgres:

# config/database.yml
production:
  <<: *default
  url: <%= ENV['PRODUCTION_POSTGRES_HOST'] %>
like image 153
Kaka Ruto Avatar answered Nov 04 '22 06:11

Kaka Ruto