Skip to content

Instantly share code, notes, and snippets.

@bazzel
Last active January 4, 2022 12:18
Show Gist options
  • Save bazzel/4255cb8646d04e7fd5a1a0a2424dca60 to your computer and use it in GitHub Desktop.
Save bazzel/4255cb8646d04e7fd5a1a0a2424dca60 to your computer and use it in GitHub Desktop.
Connect local Rails to a Postgres in Docker

Connect local Rails to a Postgres in Docker

(reference)

  1. Install Docker:
brew install docker # or brew install homebrew/cask/docker
  1. Start PG in a container:
docker run --name some-postgres -e POSTGRES_PASSWORD=<mysecretpassword> -e POSTGRES_USER=<username> -p <host_port>:5432 -d postgres[:TAG]

Once created, next time you can you docker start some-postgres

  1. Update config/database.yml:
development:
  adapter: postgresql
  encoding: unicode
  pool: 5
  host: localhost
  port: <host_port>
  password: <mysecretpassword>
  database: my_db_development
  1. Create db:
bin/rails db:create
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment