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.
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 up demo-container-db
# or just the below command:
# docker-compose up
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.