<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/how-to-run-postgresql-locally-with-docker-doh9ysr8c" -->

---
title: How to run PostgreSQL locally with Docker | daily.dev
description: A step-by-step guide demonstrates how to pull the official PostgreSQL Docker image, run a container with custom environment variables (user, password, database...
canonical: https://daily.dev/posts/how-to-run-postgresql-locally-with-docker-doh9ysr8c
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: How to run PostgreSQL locally with Docker | daily.dev
og:description: A step-by-step guide demonstrates how to pull the official PostgreSQL Docker image, run a container with custom environment variables (user, password, database...
og:url: https://daily.dev/posts/how-to-run-postgresql-locally-with-docker-doh9ysr8c
og:image: https://api.daily.dev/og/posts/DoH9YSr8c.png
og:image:alt: How to run PostgreSQL locally with Docker
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How to run PostgreSQL locally with Docker

**[Code4IT](https://daily.dev/sources/code4it)** · 5 min read · 0 upvotes · 0 comments

## Summary

A step-by-step guide demonstrates how to pull the official PostgreSQL Docker image, run a container with custom environment variables (user, password, database name) and port mapping, and connect to it using pgAdmin for local development. It covers the docker run command parameters in detail and notes that environment variables may differ across image versions, directing readers to official documentation. The piece closes by pointing to a related guide on running MongoDB in Docker and teases a future article on performing CRUD operations against PostgreSQL with C#.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.code4it.dev/blog/run-postgresql-with-docker>

## Questions this post answers

### How do I run a PostgreSQL container locally with Docker and set a custom username, password, and database name?

Pull the postgres image with docker pull postgres, then run it with docker run --name myPostgresDb -p 5455:5432 -e POSTGRES_USER=postgresUser -e POSTGRES_PASSWORD=postgresPW -e POSTGRES_DB=postgresDB -d postgres. This maps local port 5455 to the container's internal port 5432, sets the admin credentials and database name via environment variables, and runs the container in detached (background) mode.

_daily.dev surfaces practical guides like this for developers setting up local Postgres environments with Docker._

### How do I connect to a Dockerized PostgreSQL database using pgAdmin?

Connect to the server in pgAdmin using localhost as the hostname along with the environment variables (username, password, database name) defined when the container was started with docker run. The container's internal Postgres port must be mapped to a local port, such as 5455, for the connection to work from outside Docker.

_Developers wiring up database GUIs against containerized services can find setup walkthroughs like this on daily.dev._

## Similar posts on daily.dev

- [How to Back Up PostgreSQL in Docker \(Local, S3, and Plakar\) — Nick Janetakis](https://daily.dev/posts/how-to-back-up-postgresql-in-docker-local-s3-and-plakar-nick-janetakis-l64ac1yno) · Nick Janetakis · 24 upvotes · 2 comments
- [From Local Development to Production with Prisma Postgres](https://daily.dev/posts/from-local-development-to-production-with-prisma-postgres-3vyh7ogqp) · Prisma Blog · 0 upvotes · 0 comments
- [Connecting to Postgres from Spring Boot App in Heroku](https://daily.dev/posts/connecting-to-postgres-from-spring-boot-app-in-heroku-p52oop84b) · Baeldung · 0 upvotes · 0 comments

---

Tags: [#backend](https://daily.dev/tags/backend), [#docker](https://daily.dev/tags/docker), [#postgresql](https://daily.dev/tags/postgresql)

[View this post on daily.dev](https://daily.dev/posts/how-to-run-postgresql-locally-with-docker-doh9ysr8c)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"How to run PostgreSQL locally with Docker","url":"https://daily.dev/posts/how-to-run-postgresql-locally-with-docker-doh9ysr8c","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/how-to-run-postgresql-locally-with-docker-doh9ysr8c"},"datePublished":"2026-10-04T13:07:16.492Z","dateModified":"2026-10-04T13:15:34.150Z","description":"A step-by-step guide demonstrates how to pull the official PostgreSQL Docker image, run a container with custom environment variables (user, password, database...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/8b5769282c8eccc39b230a037174bf56?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/8b5769282c8eccc39b230a037174bf56?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Code4IT","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Code4IT","logo":"https://media.daily.dev/image/upload/s--OaaG4G10--/f_auto,q_auto/v1791119049/logos/code4it?_a=BAMAMicg0","url":"https://daily.dev/sources/code4it"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/how-to-run-postgresql-locally-with-docker-doh9ysr8c","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"backend,docker,postgresql","timeRequired":"PT5M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Code4IT","item":"https://daily.dev/sources/code4it"},{"@type":"ListItem","position":3,"name":"How to run PostgreSQL locally with Docker"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/how-to-run-postgresql-locally-with-docker-doh9ysr8c#faq","mainEntity":[{"@type":"Question","name":"How do I run a PostgreSQL container locally with Docker and set a custom username, password, and database name?","acceptedAnswer":{"@type":"Answer","text":"Pull the postgres image with docker pull postgres, then run it with docker run --name myPostgresDb -p 5455:5432 -e POSTGRES_USER=postgresUser -e POSTGRES_PASSWORD=postgresPW -e POSTGRES_DB=postgresDB -d postgres. This maps local port 5455 to the container's internal port 5432, sets the admin credentials and database name via environment variables, and runs the container in detached (background) mode. daily.dev surfaces practical guides like this for developers setting up local Postgres environments with Docker."}},{"@type":"Question","name":"How do I connect to a Dockerized PostgreSQL database using pgAdmin?","acceptedAnswer":{"@type":"Answer","text":"Connect to the server in pgAdmin using localhost as the hostname along with the environment variables (username, password, database name) defined when the container was started with docker run. The container's internal Postgres port must be mapped to a local port, such as 5455, for the connection to work from outside Docker. Developers wiring up database GUIs against containerized services can find setup walkthroughs like this on daily.dev."}}]}
```

