Docker, PostgreSQL, Software Development

docker-compose.yml For PgAdmin And PostgreSQL

In this post, we’ll set up PgAdmin and PostgreSQL containers with docker-compose.yml for local development. We’ll also configure PgAdmin to access the PostgreSQL database under the same bridge network. Typically, we don’t deploy a PgAdmin container alongside a PostgreSQL container in a production configuration.

Docker Compose File docker-compose.yml For PgAdmin and PostgreSQL

In the Docker compose file, we will use the following content. We are using PostgreSQL 12 and PgAdmin4 with a Web user interface.

The PostgreSQL is accessible externally via localhost:5442. However, it isn’t available to PgAdmin via the same hostname and port. Note that these containers will run under a virtual network turreta_network.

Start-Up The Containers

Next, we’re going to start up the containers. Open a command-line window and change the directory to the folder where the docker-compose.yml file is. Then, run the following command.

We get the following output on the console.

Access PgAdmin Web Interface

To access the PgAdmin web interface, open a web browser, and access http://localhost:8889.

To log in, use the PgAdmin user credentials in docker-compose.yml.

Then, create a virtual server — Right-click on the Server icon on the screen’s left-side portion. Choose the Create > Server... option. Next, provide input such as Name, Hostname/address, Port, Username, and Password.

The Name could be anything. The Hostname/address and Port refer to the PostgreSQL internal IP address and internal port number. The internal port (5432) is available in the docker-compose.yml file and credentials for the Username and Password fields.

To get the internal IP address, we need some Docker commands. Go back to the command-line console windows and run the following command.

The command displays all the running containers as follows.

Then, look for the PostgreSQL container. In this case, we have it listed with container ID 5639b3e73115. At the same time, the second container refers to the PgAdmin itself. Using that ID, we can now find out the IP address of the PostgreSQL container.

Run the following command.

The command generates the following output on the console.

Then, copy the value of the last IPAdddress entry, which is 172.20.0.3, in this case. Finally, we have the following details.

That’s how to start up PgAdmin and PostgreSQL containers in Docker using docker-compose.yml.

Video On docker-compose.yml For PgAdmin And PostgreSQL

For more information, please check the associated YouTube video for this post.

This post is part of the Docker For Developers tutorial.

Loading

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