How to Set Up PostgreSQL with Docker: A Developer-Friendly Guide

PostgreSQL is a powerful open-source relational database, widely used in modern applications. Docker, on the other hand, simplifies environment setup and management. In this guide, we'll walk you through the steps to run PostgreSQL inside a Docker container—perfect for development or testing environments.

Step 1: Install Docker

Make sure Docker is installed and running on your machine. You can download it from Docker’s official site.

Step 2: Run PostgreSQL Container

Open your terminal and execute the following command:

docker run --name dev-postgres -e POSTGRES_PASSWORD=mysecretpassword -d -p 5432:5432 postgres

This will pull the latest PostgreSQL image and run it on port 5432.

Step 3: Connect to the Database

You can now connect using any PostgreSQL client like DBeaver or psql:

psql -h localhost -U postgres

Step 4: Persist Data (Optional)

To ensure your data survives container restarts, use a volume:

docker run --name dev-postgres \
-e POSTGRES_PASSWORD=mysecretpassword \
-v pgdata:/var/lib/postgresql/data \
-d -p 5432:5432 postgres

Step 5: Manage the Container

  • docker stop dev-postgres - to stop the container
  • docker start dev-postgres - to restart it
  • docker rm dev-postgres - to remove it

 That's it! You've successfully launched a PostgreSQL instance inside Docker. This method keeps your system clean and lets you spin up databases quickly for any project.


Docker


Comments

Popular Posts

Install Ollama and Open WebUI on Ubuntu 24.04 with NVIDIA GPU Acceleration (Step-by-Step)

Install a Local AI Chatbot on Ubuntu 24.04 with Ollama and Open WebUI (Step-by-Step)

Install Ollama + Open WebUI on Ubuntu 24.04 with NVIDIA GPU Acceleration (Step-by-Step)

Trending Now

Homogeneous Nucleation on Mars: A Textbook Process Finally Observed in Nature

By the end of this piece, you will understand what the Arsia Mons Elongated Cloud is, why it resisted explanation for several years after its first observation, and what the newly published model reveals about a physical process that has never been directly confirmed on any planet's atmosphere. The cloud that broke the model Every morning during Martian spring and summer, a thin, extremely long cloud forms near the Arsia Mons volcano and gradually elongates until it stretches to more than 1,000 miles before dissipating. The cycle then repeats for several months. The formation was first recorded by a probe in 2018, and from that point onward it became a persistent puzzle for atmospheric scientists working with Mars data. The cloud's geometry, its timing, and its seasonal recurrence all pointed to a real and reproducible physical process, yet no existing model could reproduce it. For a technical audience familiar with simulation work, the situation is analogous to a product...