Docker, PostgreSQL, Software Development

docker-compose.yml for PostgreSQL

This post provides a basic docker-compose.yml to create a PostgreSQL container with an initial user account with a password. We tested with Docker for Windows, PostgreSQL 12, and Windows 10.

docker-compose.yml is Just a YAML File

A docker-compose.yml for PostgreSQL is just a text file. For example, we can use the following YAML to create and run a Docker container with a PostgreSQL with a valid user account.

Moreover, it uses specific ports and an internal network. Also, the container will keep the PostgreSQL data outside of the container itself, and multiple containers can share the data.

How to use docker-compose.yml for PostgreSQL

Before trying out any commands, we need to install Docker in our local machine. Then, verify everything works. Next, copy docker-compose.yml to some folder.

docker-compose.yml PostgreSQL

Then, open a Windows Command Line Prompt in that path

Next, run some commands. For instance, pull the image from Docker Hub to the local machine.

When we run the command, we get the following output.

Then, start the PostgreSQL container.

docker-compose.yml PostgreSQL

Once we complete all the commands, we can try to connect to the PostgreSQL database using some SQL IDE like Data Grip. Note that we can customize the content docker-compose.yml for a different PostgreSQL instance.

This post is part of the Docker For Developers tutorial.

Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.


You Might Also Like