App overview screenshotSQL and Database Guides
PostgresMySQL
Try our free SQL Client
Tools
Connecting to Postgres
Connecting to drivers
Installing Postgres
Setting up Postgres
Postgres   >   
Installing Postgres   >   
Postgres and Docker on Mac

Install Postgres in Docker on macOS

Install Docker

You can download the Docker installer from the Docker website. If you use Brew you can install Docker as a cask with:

brew install --cask docker

Run Docker by using the command line or Docker.app. The first time you do this there will be additional commands to run.

Get the Official Postgres Docker Image

Check out the list of Postgres versions available in docker. To get the latest one pull it on the command line:

docker pull postgres

After you do this you can run docker images to see your postgres image or view it in the Docker Desktop GUI:

Postgres Docker image listed in the Desktop GUI

Set the Master Password and Run

The Postgres image requires that you supply a root password. You cannot set this in the Docker Desktop GUI and must do so on the command line.

docker run --name my-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres

Ensure that Postgres is Running

Use the Docker Desktop GUI or the command line with docker ps to ensure that the container is running.

checking the postgres docker container status

Next, you can get the IP address of the Postgres database in Docker by running the following command, using the name of your instance.

docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' YOUR_CONTAINER_NAME

HOWEVER, in most cases this WILL NOT be the hostname of the database.

Username and Password for Postgres in Docker

When you first ran the container, you provided the root password for the postgres container as an environmental variable. The root user for the database is postgres.

Connect to Postgres in Docker

In the connection screen in Arctype below, we have forwarded the docker port to another local port, 9.8.7.6 and we have determined that the localhost is the interface which Docker is running on. Finally, we have the postgres user and the password we supplied to the container at runtime.

Connect to Postgres in Docker in Arctype

Press Test Connection to verify that everything is working and then Save!

Want to ask for help on databases or SQL? Join our Discord community.