samiron / java-backend-rehearse

MIT License
0 stars 1 forks source link

Setup a Postgres database container in Docker #4

Open mbozorgi opened 2 years ago

samiron commented 2 years ago
  1. Download the Postgres image docker pull postgres:14-alpine3.14
  2. Create a shell script in your folder called start-postgresh.sh
  3. Paste the following in the shell script
    
    #!/bin/bash

PGDATA_DIR="$( pwd -P )/data" echo "${PGDATA_DIR}";

if [ ! -d "${PGDATA_DIR}" ] then echo "${PGDATA_DIR} does not exists. Can not start postgres database"; echo "Please run ./docker/start-postgres.sh from the project root directory." exit 1; fi

PG_DB= PG_USER= PG_PASSWORD=

if [ "$(expr substr $(uname -s) 1 10)" == "MINGW64_NT" ]; then

In windows use the windows path format

PGDATA_DIR=cygpath -w $PGDATA_DIR; export MSYS_NO_PATHCONV=1 fi

echo "Using data directory ${PGDATA_DIR}"

docker run --name local-postgres \ -e POSTGRES_DB=$PG_DB \ -e POSTGRES_USER=$PG_USER \ -e POSTGRES_PASSWORD=$PG_PASSWORD \ -e 'PGDATA=/var/lib/postgresql/data/pgdata' \ -v ${PGDATA_DIR}:/var/lib/postgresql/data \ -p 5432:5432 \ -d postgres:14-alpine3.14

mbozorgi commented 2 years ago

it is completed an I could connect to DB through DBeaver but few questions:

  1. what is this code for in script:

if [ "$(expr substr $(uname -s) 1 10)" == "MINGW64_NT" ]; then

In windows use the windows path format

PGDATA_DIR=cygpath -w $PGDATA_DIR; export MSYS_NO_PATHCONV=1 fi

  1. I created a data folder in project and all database data was added in data folder, so should I push them all in repo? or should I have put the script some where else not in project repo
mbozorgi commented 2 years ago

So moved the script from the repo folder to a folder on top of that, so now the DB files not in repo and need to commit and push