How to install pgadmin4 with docker

We want PostgreSQL in a container and pgadmin4 in another container. And we want to connect the pgadmin4 container to the PostgreSQL container.

We do

$ sudo docker run -p 80:80 \
  --link postgres11:postgres11 \
  --name pgadmin_4pgdocker \
  -e "PGADMIN_DEFAULT_EMAIL=sql.design.company@gmail.com" \
  -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

pgadmin4

For the host name, we give postgres11 instead of 127.0.0.1 !

and then…

pgadmin4-running

We can set about tackling the work !

And the next time we reboot, we have a look on our containers

sudo docker ps -a

that gives

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_EMAIL=sql.design.company@gmail.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…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s