A script to readily create and run Postgres in Docker. This also builds pgAdmin in docker for accessing the Postgres server.
There are default values for the Postgres docker container name, the port that Postgres uses, the Postgres username, and the Postgres password. These may be overridden by setting the following environment variables:
-
PG_VERSION
The version of Postgres. (The default is15.4
) -
PG_CONTAINER
The Postgres docker container name. (The default ispg-docker
) -
PG_PORT
The port used by Postgres. (The default is5432
) -
PG_USER
The Postgres username. (The default ispostgres
. This should be fine for development, but PLEASE use best practices and change for any deployment.) -
PG_PASS
The Postgres password. (The default isdocker
. This should be fine for development, but PLEASE use best practices and change for any deployment.)
There are default values for the pgAdmin docker container, the port that pgAdmin uses, the pgAdmin username, and the pgAdmin password. These may be overridden by setting the following environment variables:
-
PGA_VERSION
The version of pgAdmin. (The default islatest
) -
PGA_CONTAINER
The pgAdmin docker image name. (The default ispg-admin
) -
PGA_PORT
The port used by pgAdmin. (The default is8010
) -
PGA_USER
The pgAdmin username. (The default ismail@mail.com
. This should be fine for development, but PLEASE use best practices and change for any deployment.) -
PGA_PASS
The pgAdmin password. (The default ispass
. This should be fine for development, but PLEASE use best practices and change for any deployment.)
Once created these containers may be accessed via a network. The default network i called postgres
. This may be overridden by setting the following environment variable:
PG_NETWORK
The network the containers can be reached on. (The default ispostgres
)
A .env
file may be placed in the same folder as this script to set environment variables. An example of the content of the .env
may look like:
PG_NETWORK=my_different_network
PGA_PORT=4242
.env-sample
may be used as a template.
Simply run:
cp .env-sample .env
This creates docker containers for a postgres database and pgAdmin. The data persists across container restarts, it is stored in Docker.
Running this script without overriding any variables (see above) should work just fine for a development environment.
Example usage:
To start the containers, simply call:
./start.sh
If a rebuild is desired, pass the "build" flag, --build
or simply -b
:
./start.sh --build
or simply
./start.sh -b
If environment variables need to be reset to defaults (with .env
overrides), pass the "reset_env" flag, --reset_env
or simply -r
:
./start.sh --reset_env
or simply
./start.sh -r
This script will stop the containers. They can be restarted with the start.sh
script and the data will persist.
Example usage:
./stop.sh