# Setting Up a PostgreSQL Container: A Quick Guide

> **Source:** [http://localhost:1313/setting-up-a-postgresql-container-a-quick-guide/](http://localhost:1313/setting-up-a-postgresql-container-a-quick-guide/)
> **Author:** [Vikash Patel](https://vikashpatel.net)
> **Published:** April 01, 2023
> **Reading Time:** 2 min
> 
> *This is the raw Markdown source of the article from the [Lorbic Technical Journal](http://localhost:1313/).*

---

Learn the simple and fast process of creating a PostgreSQL container using Docker. This guide provides both the command and a detailed explanation of the container and PostgreSQL database configuration.

## 1. Create the PostgreSQL Container:

```shell
docker run -d --name postgres \
  -e POSTGRES_PASSWORD=RunningFlying2 \
  -e PGDATA=/var/lib/postgresql/data/pgdata \
  -v postgres_data:/var/lib/postgresql/data \
  -p 5432:5432 \
  postgres:latest
  
```

## **2. Explanation:**

The above command initiates the creation of a container with the latest version of PostgreSQL. Here's a breakdown of the parameters used:

`-d: Runs the container in detached mode.`

`--name postgres: Assigns the name "postgres" to the container.`

`-e POSTGRES_PASSWORD=RunningFlying2: Sets the PostgreSQL user password to "RunningFlying2".`

`-e PGDATA=/var/lib/postgresql/data/pgdata: Specifies the PostgreSQL data directory.`

`-v postgres_data:/var/lib/postgresql/data: Creates a Docker volume named "postgres_data" for persistent data storage.`

`-p 5432:5432: Maps the container's 5432 port to the host machine's 5432 port for external access.`

`postgres:latest: Pulls and uses the latest version of the PostgreSQL image.`

## 3. Technical Details:

```
Container Name: postgres
Docker Volume: postgres_data
Host: 127.0.0.1
Port: 5432
User: postgres
Password: RunningFlying2
```

You have successfully set up a PostgreSQL container, ready to handle your database needs. The provided technical details ensure you can seamlessly connect to this container from your development or production environment.

**Explore More:**

Feel free to explore additional PostgreSQL configurations and features to tailor the container to your specific requirements.

> **Note:** For enhanced security, consider changing default passwords in production environments.

Have an amazing day.
