Monday, February 21, 2022

[SOLVED] Proper way to monitor PostgreSQL running inside a docker container

Issue

I'm running a docker container with CentOS 7 + PostgreSQL 9.4. Using this docker image.

So, after pulling the image, I've created the container, following the instructions, and exposing the PostgreSQL port 5432.

Of course, I can execute a shell in my container, by doing this

docker exec -it CONTAINER_NAME /bin/bash

After that, I'm logged as postgres user. But I need to install more software (basically, postgres related stuff, or some command line tools).

EDIT: What I'd need, for example, is to install the lsof tool (not available by default in CentOS 7, can be installed with yum install lsof).

So, I'd need a different user, able to install software. Unless...

I'm not doing things the right way, and what I really need is another container to monitorize PostgreSQL. Or even use my host machine (Mac OS X) for that. But then... How could I use commands like lsof, or htop? I need to be in the same container that runs PostgreSQL for that.

Am I right?


Solution

Ok, that was easy

docker exec -it -u root CONTAINER_NAME /bin/bash -c "yum install lsof"


Answered By - Jorge Arévalo
Answer Checked By - Mary Flores (WPSolving Volunteer)