File tree 5 files changed +73
-20
lines changed
5 files changed +73
-20
lines changed Original file line number Diff line number Diff line change
1
+ services :
2
+ redis :
3
+ image : redislabs/redismod
4
+ ports :
5
+ - ' 6379:6379'
6
+ web :
7
+ build :
8
+ context : .
9
+ target : dev-envs
10
+ stop_signal : SIGINT
11
+ ports :
12
+ - ' 8000:8000'
13
+ volumes :
14
+ - /var/run/docker.sock:/var/run/docker.sock
15
+ depends_on :
16
+ - redis
Original file line number Diff line number Diff line change 1
- FROM python:3.11.0a6-alpine3.15
1
+ # syntax=docker/dockerfile:1.4
2
+ FROM --platform=$BUILDPLATFORM python:3.10-alpine AS builder
3
+
2
4
WORKDIR /code
5
+
3
6
COPY requirements.txt /code
4
- RUN pip install -r requirements.txt --no-cache-dir
7
+ RUN --mount=type=cache,target=/root/.cache/pip \
8
+ pip3 install -r requirements.txt
9
+
5
10
COPY . /code
6
- CMD python app.py
11
+
12
+ ENTRYPOINT ["python3" ]
13
+ CMD ["app.py" ]
14
+
15
+ FROM builder as dev-envs
16
+
17
+ RUN <<EOF
18
+ apk update
19
+ apk add git bash
20
+ EOF
21
+
22
+ RUN <<EOF
23
+ addgroup -S docker
24
+ adduser -S --shell /bin/bash --ingroup docker vscode
25
+ EOF
26
+ # install Docker tools (cli, buildx, compose)
27
+ COPY --from=gloursdocker/docker / /
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ services:
24
24
web:
25
25
build: .
26
26
ports:
27
- - "5000:5000 "
27
+ - "8000:8000 "
28
28
volumes:
29
29
- .:/code
30
30
depends_on:
@@ -55,12 +55,12 @@ Listing containers must show one container running and the port mapping as below
55
55
$ docker compose ps
56
56
NAME COMMAND SERVICE STATUS PORTS
57
57
flask-redis-redis-1 "redis-server --load…" redis running 0.0.0.0:6379->6379/tcp
58
- flask-redis-web-1 "/bin/sh -c 'python …" web running 0.0.0.0:5000->5000 /tcp
58
+ flask-redis-web-1 "/bin/sh -c 'python …" web running 0.0.0.0:8000->8000 /tcp
59
59
```
60
60
61
- After the application starts, navigate to ` http://localhost:5000 ` in your web browser or run:
61
+ After the application starts, navigate to ` http://localhost:8000 ` in your web browser or run:
62
62
```
63
- $ curl localhost:5000
63
+ $ curl localhost:8000
64
64
This webpage has been viewed 2 time(s)
65
65
```
66
66
@@ -80,3 +80,14 @@ Stop and remove the containers
80
80
```
81
81
$ docker compose down
82
82
```
83
+
84
+ ## Use with Docker Development Environments
85
+
86
+ You can use this sample with the Dev Environments feature of Docker Desktop.
87
+
88
+ ![ Screenshot of creating a Dev Environment in Docker Desktop] ( ../dev-envs.png )
89
+
90
+ To develop directly on the services inside containers, use the HTTPS Git url of the sample:
91
+ ```
92
+ https://github.com/docker/awesome-compose/tree/master/flask-redis
93
+ ```
Original file line number Diff line number Diff line change @@ -11,4 +11,4 @@ def hello():
11
11
return "This webpage has been viewed " + counter + " time(s)"
12
12
13
13
if __name__ == "__main__" :
14
- app .run (host = "0.0.0.0" , debug = True )
14
+ app .run (host = "0.0.0.0" , port = 8000 , debug = True )
Original file line number Diff line number Diff line change 1
1
services :
2
- redis :
3
- image : redislabs/redismod
4
- ports :
5
- - ' 6379:6379'
6
- web :
7
- build : .
8
- ports :
9
- - " 5000:5000"
10
- volumes :
11
- - .:/code
12
- depends_on :
13
- - redis
2
+ redis :
3
+ image : redislabs/redismod
4
+ ports :
5
+ - ' 6379:6379'
6
+ web :
7
+ build :
8
+ context : .
9
+ target : builder
10
+ # flask requires SIGINT to stop gracefully
11
+ # (default stop signal from Compose is SIGTERM)
12
+ stop_signal : SIGINT
13
+ ports :
14
+ - ' 8000:8000'
15
+ volumes :
16
+ - .:/code
17
+ depends_on :
18
+ - redis
You can’t perform that action at this time.
0 commit comments