Run Postgres in a Docker container
- 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.