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.
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.
1
docker-composeup
We get the following output on the console.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
C:\Users\karldev\Desktop\dev\blogs\docker\docker-compose.yml forpgadmin+postgresql>docker-compose up
demo-container-db_1|2020-07-3109:50:50.254UTC[1]LOG:starting PostgreSQL12.3(Debian12.3-1.pgdg100+1)on x86_64-pc-linux-gnu,compiled by gcc(Debian8.3.0-6)8.3.0,64-bit
demo-container-db_1|2020-07-3109:50:50.255UTC[1]LOG:listening on IPv4 address"0.0.0.0",port5432
demo-container-db_1|2020-07-3109:50:50.255UTC[1]LOG:listening on IPv6 address"::",port5432
demo-container-db_1|2020-07-3109:50:50.264UTC[1]LOG:listening on Unix socket"/var/run/postgresql/.s.PGSQL.5432"
demo-container-db_1|2020-07-3109:50:50.299UTC[24]LOG:database system was interrupted;last known up at2020-07-3107:51:19UTC
demo-container-db_1|2020-07-3109:50:50.677UTC[24]LOG:database system was notproperly shut down;automatic recovery inprogress
demo-pgadmin4_1|/usr/local/lib/python3.8/os.py:1023:RuntimeWarning:line buffering(buffering=1)isn'tsupported inbinary mode,the defaultbuffer size will be used
demo-pgadmin4_1|returnio.open(fd,*args,**kwargs)
demo-pgadmin4_1|[2020-07-3109:50:51+0000][81][INFO]Booting worker with pid:81
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.
1
dockercontainerls
The command displays all the running containers as follows.
1
2
3
4
C:\Users\karldev>docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5639b3e73115postgres:12"docker-entrypoint.s…"3hours ago Up49minutes0.0.0.0:5442->5432/tcp docker-composeymlforpgadminpostgresql_demo-container-db_1
c906f1f96f49 dpage/pgadmin4"/entrypoint.sh"3hours ago Up49minutes443/tcp,0.0.0.0:8889->80/tcp docker-composeymlforpgadminpostgresql_demo-pgadmin4_1
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.
1
dockerinspect5639b3e73115
The command generates the following output on the console.
Tidak ada komentar:
Posting Komentar