Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@GeertVL-zz
Last active May 25, 2021 08:17
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GeertVL-zz/bd529b8cac4f8bbef7b5a8e5dc3514b2 to your computer and use it in GitHub Desktop.
Save GeertVL-zz/bd529b8cac4f8bbef7b5a8e5dc3514b2 to your computer and use it in GitHub Desktop.
How to install postgres and pgadmin in a docker environment on your local macos machine

I experienced that installing your Postgres database server on your local machine as a Docker container is not that evident. So this explains how you need to do it and what you need to take into account.

To setup your Postgres Docker container you need to run:

docker run -d -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=mysecretpassword --name postgres-server -p 5432:5432 -v pgdata:/var/lib/postgresql/data --restart=always postgres

And to run your pgadmin instance as a Docker container:

docker run -p 80:80 -e "PGADMIN_DEFAULT_EMAIL=user@domain.com" -e "PGADMIN_DEFAULT_PASSWORD=SuperSecret" -d dpage/pgadmin

Now when you go into the admin console you cannot connect to your local database server via localhost. You need to run docker inspect postgres-server to get the IP address of the container and connect with that IP address in your admin console.

Now if you want to connect with Diesel (Rust) then you need to use as server address 0.0.0.0 If you want to connect via .NET with npgsql package you need to use a connectionstring like the following:

var connectionString = "Server=localhost;Username=postgres;Password=mysecretpassword;Database=enterpreneurs";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment