This document provides instructions for setting up a PostgreSQL 14.2 database using a Dockerfile.
Contents [↑]
init-pg-user-db.sql [↑]
- Please refer to the
init-pg-user-db.sqlsection in the Setting Up PostgreSQL 14.2 with Docker Compose for the SQL script to create a user and a database.
Dockerfile [↑]
-
Create a
Dockerfilefile, and add the following content.FROM postgres:14.2 # Copy the SQL script to create a user and a database COPY ./init-pg-user-db.sql /docker-entrypoint-initdb.d/
Build the Docker image [↑]
-
Build the Docker image using the following command.
host$ docker image build -f Dockerfile -t pg-14.2 .
Start the PostgreSQL container [↑]
- Please refer to the
Containersection in the Docker commands and provisioning scripts for PostgreSQL 14.2 to start the PostgreSQL container.
Connect to the PostgreSQL service [↑]
- Please refer to the
Connect to the PostgreSQL servicesection in the Docker commands and provisioning scripts for PostgreSQL 14.2 to connect to the PostgreSQL service.
Stop container [↑]
- Please refer to the
Stop containersection in the Docker commands and provisioning scripts for PostgreSQL 14.2 to stop the PostgreSQL container.
Reference [↑]
- Reference:
- Docker Hub - Postgres
- start a
postgresinstance POSTGRES_PASSWORDPGDATADocker SecretsInitialization scripts
- start a
- Docker Hub - Postgres