Skip to content

Instantly share code, notes, and snippets.

@mcursa-jwt
Last active October 28, 2023 13:44
Show Gist options
  • Save mcursa-jwt/037528c2fb1c3ec321126e094bc7a07a to your computer and use it in GitHub Desktop.
Save mcursa-jwt/037528c2fb1c3ec321126e094bc7a07a to your computer and use it in GitHub Desktop.
local PostgreSQL container (using podman + bash script)
#!/bin/bash
HOST_MOUNT_DIR=./postgres_mount && mkdir -p $HOST_MOUNT_DIR && echo "HOST_MOUNT_DIR: $HOST_MOUNT_DIR"
podman run --name pg_db \
-p 5432:5432 \
-e POSTGRES_USER=user \
-e POSTGRES_PASSWORD=password \
-e POSTGRES_DB='pg_db' \
--volume $HOST_MOUNT_DIR:/var/lib/postgresql/data \
-d docker.io/library/postgres:16.0
# # container failed to run
if [ $? -ne 0 ]; then
echo "Removing empty mount due to launch failure."
rm -r $HOST_MOUNT_DIR
fi

using docker registry:

/etc/containers/registries.conf

unqualified-search-registries = ['docker.io']

[[registry]]
prefix = "docker.io"
location = "docker.io"

pull postgres image

$ podman pull postgres

run in the folder you want to mount the volume in

(or change $HOST_MOUNT_DIR in create_pgdb.sh)

path/to/dir$ ./create_pgdb.sh

run psql cli

psql -h localhost -p 5432 -U user -W -d pg_db

sources/reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment