
uses the -d flag to run in the background.exposes port 54320 to the host using -p.uses a named volume, my_dbdata, to store postgres data.uses the official docker postgres 13 image.Install Docker ¶Īlternatively, you can install Docker using Homebrew: brew install homebrew/cask/docker OPTION 1: Run Postgres using a single Docker command ¶ Run a postgres container I also wrote some notes on Postgres and Homebrew here. Currently I use the Homebrew Postgres for work, and Postgres in Docker for personal projects. We use Docker extensively at work, so from a mental overhead point of view, it's something I wanted to learn anyways. Admittedly, I didn't know Homebrew well, but it was frustrating.) Disadvantages of Docker are it's another layer of abstraction to learn and interact with.

(I previously had a problem where Homebrew upgraded Postgres when I didn't expect it to and my existing database became incompatible. Running in Docker allows keeping my database environment isolated from the rest of my system and allows running multiple versions and instances. These are my notes for running Postgres in a Docker container for use with a local Django or Rails development server running on the host machine (not in Docker). Date: | Modified: | Tags: docker, linux, mac, sql Hopefully this article will save your time. If everything goes well we should see: postgis_test=#CREATE EXTENSION postgis Ĭheck your PostGIS version SELECT PostGIS_Version() This command should show the psql command prompt psql (10.0)Ĭreating extension for PostGIS. Run the initdb command again initdb /usr/local/var/postgresĬreate a new database createdb postgis_test Remove old database file rm -r /usr/local/var/postgres With an argument other than "/usr/local/var/postgres". The directory "/usr/local/var/postgres" or run initdb If you want to create a new database system, either remove or empty If terminal shows an error initdb: directory "/usr/local/var/postgres" exists but is not empty Start PostgreSQL server pg_ctl -D /usr/local/var/postgres startĬreate Database initdb /usr/local/var/postgres Install PostGIS with Homebrew brew install postgis Install Postgres with Homebrew brew install postgres

Remove previous versions of PostgreSQL brew uninstall -force postgresqlĭelete all Files of Postgres rm -rf /usr/local/var/postgres I have went through their official sites and many other document to know about the installation process and found out these processes, to reinstall the PostgreSQL if another version of PostgreSQL is installed previously and installing PostGIS in Mac OS. When I was setting up a Rails project in my local machine it requires PostGIS setup to run the migration. It adds supports for geographic objects allowing location queries to be run in SQL.

PostGIS is spatial database extender for PostgreSQL object-relational database.
