In the startUpScript.sh, we first initialized the PostgreSQL database and then created a dummy database baeldung. Su -l postgres -c "/usr/pgsql-11/bin/pg_ctl -D /var/lib/pgsql/11/data -l /tmp/pg_logfile start" Su -l postgres -c /usr/pgsql-11/bin/initdb Let's look into the startUpScript.sh file: #!/bin/bash In the above Dockerfile, we used startUpScript.sh to start the PostgreSQL database server on successful installation.
#Psql restore dump mac os 10.12 install#
& yum install -y postgresql11-server postgresql11-contrib \ĬMD RUN yum install -y epel-release maven wget \ Here we'll create a Dockerfile that will contain all the required commands to install Postgres using CentOS as the base image: FROM centos:7 We can also set up the PostgreSQL database server by creating a customized Dockerfile. Let's now use the psql to connect with the database: Psql is a command-line utility used to access PostgreSQL databases interactively. To back up the data, we also mounted the /var/lib/postgresql/data directory to the /data directory of the host machine of the postgres container. We exposed the 5432 port on the host using the “-p 5432:5432” in the docker run command. By default, the PostgreSQL database runs on the 5432 port.
#Psql restore dump mac os 10.12 password#
The above command uses environment variables POSTGRES_USER and POSTGRES_PASSWORD to set the username and password for the PostgreSQL database. Now, we'll run the Docker container using postgres:latest image using the below command: $ docker run -itd -e POSTGRES_USER=baeldung -e POSTGRES_PASSWORD=baeldung -p 5432:5432 -v /data:/var/lib/postgresql/data -name postgresql postgresĥaeda2b20a708296d22db4451d0ca57e8d23acbfe337be0dc9b526a33b302cf5 Status: Downloaded newer image for postgres:14.2 We can also pull a particular version of the postgres image using the below command: $ docker pull postgres:14.2ĭigest: sha256:e3d8179786b8f16d066b313f381484a92efb175d1ce8355dc180fee1d5fa70ec In the above command, we pulled the postgres latest stable image. Status: Downloaded newer image for postgres:latest To run a PostgreSQL using Docker, we first need to pull the postgres public image available on Docker Hub: $ docker pull postgresĭigest: sha256:ab0be6280ada8549f45e6662ab4f00b7f601886fcd55c5976565d4636d87c8b2