Minggu, 13 Februari 2022

POSGRES12 & PGADMIN4-docker

 

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 [crayon-6209937a6b596082291230-i/] For PgAdmin and PostgreSQL

The Docker compose file, we’re going to 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 NameHostname/addressPortUsername, 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 [crayon-6209937a6b5bb140198936-i/] For PgAdmin And PostgreSQL

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


==================================================

Copy this snippet into your docker-compose.yml file:

db:
  image: pm990320/docker-postgres8:8.0.2
  environment:
    - POSTGRES_USER=docker
    - POSTGRES_PASSWORD=docker
    - POSTGRES_DATABASE=docker
  ports:
    - 5432:5432

Alternatively, run this command to run the container:

docker run -p 5432:5432 -e POSTGRES_USER=docker -e POSTGRES_PASSWORD=docker -e POSTGRES_DATABASE=docker pm990320/docker-postgres8:8.0.2

This post is part of the Docker For Developers tutorial.

 4987 total views , 1 views today

Tidak ada komentar:

Posting Komentar