Introduction
In this article, the focus will be just to show how to run a PostgreSQL database server using a docker container. Furthermore, the process for running the docker container will be in a local device running using Microsoft Windows operating system. Before going on further, there are several steps which is important as a preparation. In this context, the preparation process is only for managing to have a running docker service. For the local device running using Microsoft Windows operating system, in order to run a docker service just use Docker Desktop application. So, in order to simulate how to run PostgreSQL database server using a docker container in Microsoft Windows, execute the following steps :
-
First of all, just install Docker Desktop application. In order to be able to do that as a reference check for an article in ‘How to Install Docker Desktop in Microsoft Windows‘.
- After successfully installing Docker Desktop, make sure to check that the docker service is running.
How to Run PostgreSQL Database Server using a Docker Container in Microsoft Windows
After finishing the preparation exist in the above part, just continue on the steps by following these steps :
-
First of all, just pull the PostgreSQL database docker image by executing the following command :
C:\database\postgresql>docker pull postgres Using default tag: latest latest: Pulling from library/postgres 8740c948ffd4: Pull complete c8dbd2beab50: Pull complete 05d9dc9d0fbd: Pull complete ddd89d5ec714: Pull complete f98bb9f03867: Pull complete 0554611e703f: Pull complete 64e0a8694477: Pull complete 8b868a753f47: Pull complete 12ed9aefbab3: Pull complete 825b08d51ffd: Pull complete 8f272b487267: Pull complete ba2eed7bd2cc: Pull complete ff59f63f47d6: Pull complete Digest: sha256:6b07fc4fbcf551ea4546093e90cecefc9dc60d7ea8c56a4ace704940b6d6b7a3 Status: Downloaded newer image for postgres:latest docker.io/library/postgres:latest C:\database\postgresql>
-
After successfully pulling the PostgreSQL database server docker image, just execute the following command to check the existence of it :
C:\database\postgresql>docker image list -a REPOSITORY TAG IMAGE ID CREATED SIZE postgres 14 9500676ec231 3 hours ago 995MB C:\database\postgresql>
-
Since the PostgreSQL database server docker image already exist locally, just execute the following command to run a docker container using that image as follows :
C:\database\postgresql>docker run --name postgres-0 -e POSTGRES_PASSWORD=password -d -p 5432:5432 postgres c51b3b344bd301cbdd4f9c4649fdda901e078c0ebbd3ac679caff519fa72bb9f C:\database\postgresql>
-
Following after, just check whether the docker container exist as a result from the previous command execution as follows :
C:\database\postgresql>docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c51b3b344bd3 postgres "docker-entrypoint.s…" 10 seconds ago Up 9 seconds 0.0.0.0:5432->5432/tcp postgres-db C:\database\postgresql>
-
Last step, just access the PostgreSQL database server in order to prove that it is already running by executing the command as follows :
C:\database\postgresql>docker exec -it postgres-db psql -U postgres psql (15.1 (Debian 15.1-1.pgdg110+1)) Type "help" for help. postgres=# \q
Another way to prove the PostgreSQL database server is currently running, just access the docker container by executing the following command :
C:\database\postgresql>docker exec -it postgres-db bash root@c51b3b344bd3:/# psql -Upostgres psql (15.1 (Debian 15.1-1.pgdg110+1)) Type "help" for help. postgres=# \q root@c51b3b344bd3:/# psql -Upostgres psql (15.1 (Debian 15.1-1.pgdg110+1)) Type "help" for help. postgres=#