Wednesday, September 4, 2024

PostgreSQL instance on Windows with Docker Desktop

Running a database instance on your development environment is crucial, when you need a stable RDBMS for software development. Now we'll discuss how to install and configure a PostgreSQL instance with Docker Desktop on Windows.

Our starting point will be


We'll download the PostgreSQL image from this website. When you open it, press the "Copy" button to copy the Docker command:

Next, open a command line tool, and paste the recently copied command and execute it:




This will download the image to your machine, let's switch to Docker Desktop for Windows to verify the given image has been downloaded:

As you can see, I already had an image, but the first one is the latest that I downloaded now.

To run your database, open a command line tool again, and enter:

docker run -p 5432:5432 --name <container_name> -e POSTGRES_DB=<database_name> -e POSTGRES_PASSWORD=<db_password> -d postgres

Let's talk about the bold texts in the command:
  • -p 5432:5432: The first number is the port number where postgres is running, the second one is where the first one forwarded to, so inside the container the Postgres instance will be available on 5432 port, and when you want to reach PgSQL "outside", you can use the same port, but of course you can define any port number,
  • <container_name> this is the name of the container that you want to create, and this will appear in your containers list,
  • <database_name> this will be the name of the database that you want to create,
  • <db_password> this will be the password of your database
If you did everything properly, you will see your running container:

To verify the database is up and running, open a database client. I prefer DbVisualizer, because it's a free and simple software. Open DbVisualizer and create a new connection:

UserId must be "postgres", the password should be the credential that you configured in the Docker run command and the port should be 5432.

If you see something similar, the connection is stable!



No comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Configure and use VSCode for Java web development

Embarking on Java web development often starts with choosing the right tools that streamline the coding process while enhancing productivity...