Member-only story
Setting Up PostgreSQL in Docker: A Step-by-Step Guide
PostgreSQL is a powerful, open-source object-relational database system. Running PostgreSQL in a Docker container is an efficient way to set up and manage your database. This guide will walk you through setting up PostgreSQL in Docker, from installation to configuration.
Prerequisites
Before you begin, ensure that you have the following installed on your system:
1. Docker: You can download Docker from the official website.
2. Docker Compose (optional but recommended): This tool simplifies multi-container Docker setups.
3. Basic knowledge of the command line.
Step 1: Pull the PostgreSQL Docker Image
To get started, pull the official PostgreSQL Docker image from Docker Hub:
docker pull postgres
This command fetches the latest PostgreSQL image. If you need a specific version, specify it, like so:
docker pull postgres:15.3
Step 2: Run the PostgreSQL Container
Run a PostgreSQL container using the docker run command:
docker run --name postgres-container -e POSTGRES_USER=myuser -e POSTGRES_PASSWORD=mypassword -e POSTGRES_DB=mydatabase -p 5432:5432 -d postgres
Here’s a breakdown of the flags:
- — name…