Postgres Docker Container

Created at: 2024-10-22

Here is a command for running a throw-away postgres container:

HOST_PORT=5400
VERSION=15
PASSWORD=postgres
TEST_NAME=my_sweet_test
CONTAINER_NAME=postgres_${VERSION}_${TEST_NAME}
VOLUME_NAME=${CONTAINER_NAME}_data

# Get the container image.
docker pull postgres:$VERSION

# Run the actual container
docker run \
    --name ${CONTAINER_NAME} \
    -e POSTGRES_PASSWORD=${PASSWORD} \
    -d -p ${HOST_PORT}:5432 \
    -v ${VOLUME_NAME}:/var/lib/postgresql/data \
    --shm-size=4g \
    postgres:$VERSION

To stop and remove everything:

docker stop $CONTAINER_NAME
docker rm -v $CONTAINER_NAME