Access PG in Docker from a GUI

Post by Saul Shanabrook

Update: Since changing from links to Docker Compose's new networking, the command would be: docker run -it -p 5432:5432 --rm --net=djangodiet_ verb/socat:alpine TCP-LISTEN:5432 TCP:djangodiet_db_1:5432.

I was recently trying to debug the state of my Django database, which was running in a Docker container. I wanted to connect to it with the GUI Postico.

The easiest way to do this would be tell Docker to expose port 5432 on the PG container. However, I didn't feel like changing my Docker Compose file to add the expose:\n - 5432:5432 line.

Instead, I figured I could just create a new container, link to that container, expose a port on the new container, and forward traffic from the link out the exposed port. Something like this:

docker run -it --link djangodiet_db_1:postgres -p 5432:5432 --rm verb/socat:alpine TCP-LISTEN:5432,fork TCP:postgres:5432  

where djangodiet_db_1 is the name of my original postgres container.

Then I can just connect to docker-machine ip default:

thx socat and a nice small docker image of it