We want PostgreSQL in a container and pgadmin4 in another container. And we want to connect the pgadmin4 container to the PostgreSQL container.
$ sudo docker run -p 80:80 \ --link postgres11:postgres11 \ --name pgadmin_4pgdocker \ -e "PGADMIN_DEFAULT_EMAILfirstname.lastname@example.org" \ -e "PGADMIN_DEFAULT_PASSWORD=secret" \ -d dpage/pgadmin4
80:80 means that the port 80 of the container is tunneled to the port 80 of the host.
–link postgres11:postgres11 means that we link the pgadmin4 container to the postgres11 container. Remember that we wrote in the definition of the postgres11 container the name of the host :
... --name postgres11 ...
and then we open our browser on 127.0.0.1:80, we give the username/password as defined above and when create a server, we give as host name postgres11
For the host name, we give postgres11 instead of 127.0.0.1 !
We can set about tackling the work !
And the next time we reboot, we have a look on our containers
$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c8f82e1fd7f6 dpage/pgadmin4 "/entrypoint.sh" 27 hours ago Exited (255) 10 minutes ago 0.0.0.0:80->80/tcp, 443/tcp jolly_mendel c9159dae8aae postgres "docker-entrypoint.s…" 27 hours ago Up About a minute 0.0.0.0:5432->5432/tcp postgres11
They are of course there and their CONTAINER ID are the same. By the way, the creators of containers are used to give them poetical names like jolly_mendel.
And we restart them
$ sudo docker start c9159dae8aae $ sudo docker start c8f82e1fd7f6
So nice !
And if we want that pgadmin4 reaches the cluster located on the host, we do
$ sudo docker run \ -d \ --rm \ --net=host \ -e "PGADMIN_DEFAULT_EMAILemail@example.com" \ -e "PGADMIN_DEFAULT_PASSWORD=secret" \ --name pgadmin_4_local dpage/pgadmin4
We have to stop pgadmin_4pgdocker before starting the previous command.
At this very moment, I don’t know how to manage two pgadmin4 containers simultaneously.
Or to have two clusters in pgadmin4 : one for the PostgreSQL cluster in the container and one for the PostgreSQL on the host.
A bit patience…