mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 07:08:01 +00:00
Add Run A Basic PostgreSQL Server In Docker as a Docker TIL
This commit is contained in:
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
||||
|
||||
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
||||
|
||||
_1394 TILs and counting..._
|
||||
_1395 TILs and counting..._
|
||||
|
||||
---
|
||||
|
||||
@@ -194,6 +194,7 @@ _1394 TILs and counting..._
|
||||
### Docker
|
||||
|
||||
- [Configure Different Host And Container Ports](docker/configure-different-host-and-container-ports.md)
|
||||
- [Run A Basic PostgreSQL Server In Docker](docker/run-a-basic-postgresql-server-in-docker.md)
|
||||
|
||||
### Elixir
|
||||
|
||||
|
||||
36
docker/run-a-basic-postgresql-server-in-docker.md
Normal file
36
docker/run-a-basic-postgresql-server-in-docker.md
Normal file
@@ -0,0 +1,36 @@
|
||||
# Run A Basic PostgreSQL Server In Docker
|
||||
|
||||
Here is a basic `docker-compose.yml` file for spinning up a Docker container
|
||||
that runs a PostgreSQL server on port 5432. This is what I use to create a
|
||||
locally-running PostgreSQL server that lives inside a docker container.
|
||||
|
||||
```yaml
|
||||
version: "3.7"
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:latest
|
||||
restart: always
|
||||
environment:
|
||||
- POSTGRES_USER=postgres
|
||||
- POSTGRES_PASSWORD=postgres
|
||||
- POSTGRES_DB=postgres
|
||||
ports:
|
||||
- "5432:5432"
|
||||
volumes:
|
||||
- ./postgres-data:/var/lib/postgresql/data
|
||||
```
|
||||
|
||||
To create the docker container and start it up, run the following command from
|
||||
the same directory where you put this file:
|
||||
|
||||
```bash
|
||||
$ docker compose up
|
||||
```
|
||||
|
||||
This command knows to look for the `docker-compose.yml` file though you can
|
||||
always be explicit about the file with the `-f` option.
|
||||
|
||||
This configuration points at `postgres:latest` which currently is `16.1`. To
|
||||
run a different major version, you can change the `image` to something like
|
||||
`postgres:15`. See [Docker Hub](https://hub.docker.com/_/postgres) for more
|
||||
options.
|
||||
Reference in New Issue
Block a user