Skip to content

Commit f716bfb

Browse files
authored
add configuration to use django sample with Docker Dev Environments feature (#252)
Signed-off-by: Guillaume Lours <[email protected]>
1 parent 34115dc commit f716bfb

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

django/.docker/docker-compose.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
services:
2+
web:
3+
build:
4+
context: app
5+
target: dev-envs
6+
ports:
7+
- '8000:8000'
8+
volumes:
9+
- /var/run/docker.sock:/var/run/docker.sock

django/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,10 @@ Stop and remove the containers
5050
```
5151
$ docker compose down
5252
```
53+
## Use with Docker Development Environments
54+
55+
You can use this sample with the Dev Environments feature of Docker Desktop.
56+
To develop directly the web service inside a container, you just need to use the https git url of the sample:
57+
`https://github.com/docker/awesome-compose/tree/master/django`
58+
59+
![page](../dev-envs.png)

django/app/Dockerfile

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
1-
FROM python:3.7-alpine
1+
# syntax=docker/dockerfile:1.4
2+
3+
FROM --platform=$BUILDPLATFORM python:3.7-alpine AS builder
24
EXPOSE 8000
35
WORKDIR /app
46
COPY requirements.txt /app
57
RUN pip3 install -r requirements.txt --no-cache-dir
68
COPY . /app
79
ENTRYPOINT ["python3"]
810
CMD ["manage.py", "runserver", "0.0.0.0:8000"]
11+
12+
FROM builder as dev-envs
13+
RUN <<EOF
14+
apk update
15+
apk add git
16+
EOF
17+
18+
RUN <<EOF
19+
addgroup -S docker
20+
adduser -S --shell /bin/bash --ingroup docker vscode
21+
EOF
22+
# install Docker tools (cli, buildx, compose)
23+
COPY --from=gloursdocker/docker / /
24+
CMD ["manage.py", "runserver", "0.0.0.0:8000"]

django/compose.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
services:
22
web:
3-
build: app
3+
build:
4+
context: app
5+
target: builder
46
ports:
57
- '8000:8000'

0 commit comments

Comments
 (0)