An open API service indexing awesome lists of open source software.

https://github.com/erkobridee/docker-postgresql

Explore how to use the PostgreSQL on a Docker Container
https://github.com/erkobridee/docker-postgresql

docker docker-compose pgadmin postgres

Last synced: about 2 months ago
JSON representation

Explore how to use the PostgreSQL on a Docker Container

Awesome Lists containing this project

README

          

# docker-postgresql

Explore how to use the PostgreSQL on a Docker Container

🚨🚧 THIS IS A TESTING REPOSITORY TO BE USED LOCALLY ONLY 🚧🚨

## Commands

### Docker Container

1\. Pull the PostgreSQL Docker Image

```sh
docker pull postgres:17-alpine
```

2\. Run a PostgreSQL Container

```sh
docker run -d \
--name test-postgres-container \
-e POSTGRES_USER=admin \
-e POSTGRES_PASSWORD=secret \
-e POSTGRES_DB=test \
-p 5432:5432 \
postgres:17-alpine
```

with Volume

```sh
docker run -d \
--name test-postgres-container \
-e POSTGRES_USER=admin \
-e POSTGRES_PASSWORD=secret \
-e POSTGRES_DB=test \
-p 5432:5432 \
-v test_pgdata:/var/lib/postgresql/data \
postgres:17-alpine
```

check the Docker volumes ( [doc ref](https://docs.docker.com/reference/cli/docker/volume/ls/) )

```sh
docker volume ls
```

check the disk used by Docker ( [doc ref](https://docs.docker.com/reference/cli/docker/system/df/) )

```sh
docker system df
```

3\. Connect to PostgreSQL

```sh
docker exec -it test-postgres-container psql -U admin -d test
```

Test query

```sql
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
email TEXT UNIQUE NOT NULL
);

INSERT INTO users (name, email) VALUES ('John Snow', 'john@snow.got');

SELECT * FROM users;
```

4\. Stop Container

```sh
docker stop test-postgres-container
```

5\. Remove Container

```sh
docker rm -f test-postgres-container
```

### Docker Compose

1\. run on background

```sh
docker compose up -d
```

2\. stop

```sh
docker compose down
```

#### pgAdmin server config

Defined by `pgadmin_entrypoint.sh` and set as executable file ( `chmod +x pgadmin_entrypoint.sh` )

## Useful links

- [PostgreSQL](https://www.postgresql.org/)

- [pgAdmin](https://www.pgadmin.org/) - The Most Popular PostgreSQL Admin Tool

- [Docker](https://www.docker.com/)
- [Install Docker Engine on Ubuntu | Docker Docs](https://docs.docker.com/engine/install/ubuntu/)

```sh
sudo apt install \
docker-ce docker-ce-cli \
containerd.io \
docker-buildx-plugin \
docker-compose-plugin
```

- [Use Docker Compose | Docker Docs](https://docs.docker.com/get-started/workshop/08_using_compose/)

- [Docker Compose | GeeksforGeeks](https://www.geeksforgeeks.org/devops/docker-compose/)

- [Docker Compose Cheatsheet — Most useful commands with examples | by Rost Glukhov - Medium](https://medium.com/@rosgluk/docker-compose-cheatsheet-most-useful-commands-with-examples-4fbc3d2b5deb)

- [postgres - Official Image | Docker Hub](https://hub.docker.com/_/postgres/)

- [Getting Started with PostgreSQL on Docker | Postgres Guide](https://postgres.guide/docs/getting-started/)

- [PostgreSQL in Docker: A Step-by-Step Guide for Beginners | DataCamp](https://www.datacamp.com/tutorial/postgresql-docker)

- [Dump & Restore PostgreSQL database in a Docker | Peter's Notes](https://petersnotes.com/posts/dump--restore-postgresql-database-in-a-docker/)

- [Visualizing your PostgreSQL databases with pgAdmin | Docker Docs](https://docs.docker.com/guides/pgadmin/)

- [How to create a docker-compose setup with PostgreSQL and pgAdmin4 | Hands On Programming](https://www.handsonprogramming.io/blog/2024/11/postgresql)

- [[GitHub] matschik/docker-compose-postgres-pgadmin](https://github.com/matschik/docker-compose-postgres-pgadmin) - A Docker Compose setup for PostgreSQL and pgAdmin, ideal for development and testing environments.