Skip to content

Commit 4ea6433

Browse files
authored
Use a volume for PostgreSQL data
1 parent 5f0c404 commit 4ea6433

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

docker/docker-compose-for-django-development.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ I ended up with this `docker-compose.yml` file in the root of the project:
1313
```yaml
1414
version: "3.1"
1515

16+
volumes:
17+
postgresql-data:
1618
services:
1719
database:
1820
image: postgis/postgis:13-3.1
@@ -21,6 +23,8 @@ services:
2123
- "5432"
2224
ports:
2325
- "5432:5432"
26+
volumes:
27+
- postgresql-data:/var/lib/postgresql/data
2428
environment:
2529
POSTGRES_USER: postgres
2630
POSTGRES_DB: mydb
@@ -53,7 +57,11 @@ services:
5357
depends_on:
5458
- database
5559
```
56-
The `db` container runs PostGIS. The `web` container runs the Django development server, built using the custom `Dockerfile.dev` Dockerfile. The `migrations` container simply runs the apps migrations and then terminates - with `depends_on` used to ensure that migrations run after the hdatabase server starts and before the web server.
60+
The `db` container runs PostGIS. It uses a named volume to persist PostgreSQL data in between container restarts.
61+
62+
The `web` container runs the Django development server, built using the custom `Dockerfile.dev` Dockerfile.
63+
64+
The `migrations` container simply runs the apps migrations and then terminates - with `depends_on` used to ensure that migrations run after the hdatabase server starts and before the web server.
5765

5866
The `container_name: myapp` field on the `web` container is a convenience which means you can later run commands like this:
5967

0 commit comments

Comments
 (0)