File tree Expand file tree Collapse file tree 5 files changed +73
-20
lines changed Expand file tree Collapse file tree 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+
24WORKDIR /code
5+
36COPY 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+
510COPY . /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:
2424 web:
2525 build: .
2626 ports:
27- - "5000:5000 "
27+ - "8000:8000 "
2828 volumes:
2929 - .:/code
3030 depends_on:
@@ -55,12 +55,12 @@ Listing containers must show one container running and the port mapping as below
5555$ docker compose ps
5656NAME COMMAND SERVICE STATUS PORTS
5757flask-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
5959```
6060
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:
6262```
63- $ curl localhost:5000
63+ $ curl localhost:8000
6464This webpage has been viewed 2 time(s)
6565```
6666
@@ -80,3 +80,14 @@ Stop and remove the containers
8080```
8181$ docker compose down
8282```
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():
1111 return "This webpage has been viewed " + counter + " time(s)"
1212
1313if __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 11services :
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