Skip to content

erkobridee/docker-postgresql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

docker pull postgres:17-alpine

2. Run a PostgreSQL Container

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

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 )

docker volume ls

check the disk used by Docker ( doc ref )

docker system df

3. Connect to PostgreSQL

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

Test query

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

docker stop test-postgres-container

5. Remove Container

docker rm -f test-postgres-container

Docker Compose

1. run on background

docker compose up -d

2. stop

docker compose down

pgAdmin server config

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

Useful links

About

Explore how to use the PostgreSQL on a Docker Container

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages