# 1.2.5 - Running Postgres and pgAdmin with Docker-Compose

Youtube Video | \~9 min

{% embed url="<https://www.youtube.com/watch?v=hKI6PkPhpa0&list=PL3MmuxUbc_hJed7dXYoJw8DoCuVHhGEQb&index=9&pp=iAQB>" %}
<https://www.youtube.com/watch?v=hKI6PkPhpa0&list=PL3MmuxUbc_hJed7dXYoJw8DoCuVHhGEQb&index=9&pp=iAQB>
{% endembed %}

:writing\_hand: This video is an introduction to <mark style="background-color:blue;">docker-compose</mark> where we will learn how to configure postgres and pgadmin in a <mark style="background-color:blue;">docker-compose</mark> yaml file. We will then learn how to run and close it down.

{% hint style="info" %} <mark style="background-color:blue;">docker-compose</mark> comes with docker desktop on Mac & Windows. You can read more about docker compose here <https://docs.docker.com/compose/>
{% endhint %}

"Compose simplifies the control of your entire application stack, making it easy to manage services, networks, and volumes in a single, comprehensible YAML configuration file. Then, with a single command, you create and start all the services from your configuration file." - <https://docs.docker.com/compose/>. Now, we do not need to do the network steps we did in 1.2.3 to connect our two containers under a network, but instead can use a docker-compose YAML file.

:pencil: docker-compose.yaml

```yaml
services:
  pgdatabase:
    image: postgres:13
    environment:
      - POSTGRES_USER=root
      - POSTGRES_PASSWORD=root
      - POSTGRES_DB=ny_taxi
    volumes:
      - "./ny_taxi_postgres_data:/var/lib/postgresql/data:rw"
    ports:
      - "5432:5432"
  pgadmin:
    image: dpage/pgadmin4
    environment:
      - PGADMIN_DEFAULT_EMAIL=admin@admin.com
      - PGADMIN_DEFAULT_PASSWORD=root
    ports:
      - "8080:80"
```

:black\_medium\_square: Terminal runs the docker-compose.yaml  and `-d` so we can still use our terminal

```bash
docker-compose up -d
```

:black\_medium\_square: Terminal stops the run

```bash
docker-compose down
```

:eyes: Note that in the current docker compose, we now write `compose.yaml` files and run it using `docker compose up -d` so there is a space between the works instead of a dash -.

### Resources

{% embed url="<https://medium.com/@jewelski/quickly-set-up-a-local-postgres-database-using-docker-5098052a4726>" %}

:books: [Docker compose fundamentals](https://docs.docker.com/compose/gettingstarted/)

:books: [Docker-compose Example ](https://docs.docker.com/compose/gettingstarted/)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://data-engineering-zoomcamp-2025-t.gitbook.io/tinker0425/module-1/1.2-docker-and-docker-compose/1.2.5-running-postgres-and-pgadmin-with-docker-compose.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
