Learning how to run PostgreSQL in a Docker Container

            # Learning how to run Postgres in a Docker container

The steps that I took

  1. Find a suitable docker image on docker hub. I picked a recent (10.5) Alpine (lightweight version).

{{EJS1-1}}

  1. Then {{EJS1-5}} will confirm that the image is available.
  2. Now run the image (i.e. build an instance of that image henceforth known as container). In addition, we will name the image, map the port and pass in an environment variable with the password for log-on.

{{EJS1-2}}

You could now connect to the database from an application (e.g. I used TablePlus or use a locally installed version of pgAdmin4.

Alternatively, you could run both the database and pgAdmin4 together in separate but networked containers.

{{EJS1-3}}

To connect, you now need to navigate to {{EJS1-6}} on your local machine, enter {{EJS1-7}} as the username and {{EJS1-8}} as the password to log-on, then follow the link to add a server. Then configure the server settings as below (in particular, note that the host is not {{EJS1-9}} but the name of the host you set up in the docker-compose file.

Screenshot of Safari  20 10 2018 08 11 50

You can also use the psql interactive terminal client via docker exec. First use {{EJS1-10}} to identify the container that is running PostgreSQL, then launch via bash using {{EJS1-11}}.

{{EJS1-4}}