From 92d732c7691564d8087eb3666faba270dcc25f8d Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Sat, 15 Mar 2025 14:03:55 -0500 Subject: [PATCH] Add Check Postgres Version Running In Docker Container as a Docker TIL --- README.md | 3 +- ...res-version-running-in-docker-container.md | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 docker/check-postgres-version-running-in-docker-container.md diff --git a/README.md b/README.md index ba8a8ed..84e5bb2 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186). -_1618 TILs and counting..._ +_1619 TILs and counting..._ See some of the other learning resources I work on: - [Ruby Operator Lookup](https://www.visualmode.dev/ruby-operators) @@ -224,6 +224,7 @@ If you've learned something here, support my efforts writing daily TILs by ### Docker +- [Check Postgres Version Running In Docker Container](docker/check-postgres-version-running-in-docker-container.md) - [Configure Different Host And Container Ports](docker/configure-different-host-and-container-ports.md) - [List Running Docker Containers](docker/list-running-docker-containers.md) - [Prevent Containers From Running On Startup](docker/prevent-containers-from-running-on-startup.md) diff --git a/docker/check-postgres-version-running-in-docker-container.md b/docker/check-postgres-version-running-in-docker-container.md new file mode 100644 index 0000000..e8f9bd8 --- /dev/null +++ b/docker/check-postgres-version-running-in-docker-container.md @@ -0,0 +1,28 @@ +# Check Postgres Version Running In Docker Container + +I have a docker container that I'm using to run a PostgreSQL development +database on my local machine. It was a while ago when I set it up, so I can't +remember specifically which major version of PostgreSQL I am using. + +I use `docker ps` to list the names of each container. + +```bash +$ docker ps --format "{{.Names}}" +still-postgres-1 +better_reads-postgres-1 +``` + +I grab the one I am interested in. In this case, that is `still-postgres-1`. + +Then I can execute a `select version()` statement with `psql` against the +container with that name like so: + +```bash +$ docker exec still-postgres-1 psql -U postgres -c "select version()"; + version +--------------------------------------------------------------------------------------------------------------------- + PostgreSQL 16.2 (Debian 16.2-1.pgdg120+2) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit +(1 row) +``` + +And there I have it. I'm running Postgres v16 in this container.