PostgreSQL with Podman

date:

tags: postgres postgresql database podman

categories: Database Management

I have previously worked with Postgres as a database. Check out a previous post if you are not familiar with Postgres. In that post I ran Postgres as a docker container and used psql to execute commands against the database. Today I am going to look at running Postgres with Podman as an alternative container engine and another container “adminer” which provides a web UI for interacting with a database. If you are not familiar with Podman, check out a previous post about alternatives to Docker.

Create a pod

With a podman pod, I can spin up several containers related to a database. To start, here is a pod with:

  1. A postgresql server
  2. a adminer container (a php app to interact with databases)
  3. a container that runs the psql binary attached to your terminal

without the -d flag, you will need to open a new terminal for each subsequent container.

Generally here I will not add that flag unless the container is meant to act as a server. The adminer and psql containers performs database operations so I would not recommend to leave that running.

A new pod can be created with any of these containers or with the command:

1
podman pod create postgresp

To create containers inside a pod, add the pod flag:

1
podman run -it --rm --pod postgresp -p 8080:8080 docker.io/adminer

This will attach the current terminal session to the adminer container.

To create a postgres container, open a new terminal:

1
podman run --pod postgresp --name postgres_test -e POSTGRES_PASSWORD=supersecretpass -dt docker.io/postgres

Once the database is running you can access it with a browser on your localhost port 8080.

You can open a psql shell with another container created within the pod:

1
podman run -it --rm --pod postgresp docker.io/postgres psql -h postgres_test -U postgres
comments powered by Disqus