dwyl / dwyl/learn-postgresql

Run Postgres in a Docker container

Open
#55 1 comment 2 reactions 1 assignee Claimed by @SimonLab View on GitHub
enhancement
Dominant language
JavaScript
Stars
346
Forks
37
PR merge metrics
No merged PRs in 30d

Description

We can add a section on how to run postgres in a Docker container. This is useful when you don't want to setup Postgres on your machine.

1 Get Postgres from docker:
`docker pull postgres`

2 Start a new postgres container:
`docker run --rm --name pg-docker -e POSTGRES_PASSWORD=docker -e POSTGRES_DB=mydb -d -p 5432:5432 postgres`

where --rm clean up the container, ie remove the container when it stops, see https://docs.docker.com/engine/reference/run/#clean-up-rm

--name is the name of the container, you can choose the name you want

-e for defining some environment variables, here we are setting the password and the database name

-d to run the container as a deamon, ie as a background process

-p to expose the port of the container, this allow us to connect to postgres with psql for example

3 Check the container has been created with `docker container ls`

4 Connect to the database with psql
`psql -h localhost -U postgres -d mydb`

5 To stop postgres and the container: `docker stop pg-docker` where `pg-docker` is the name of the container

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.