Skip to content

Commit 8b0f5ad

Browse files
authored
Merge pull request dockersamples#311 from dockersamples/fix-python-reloading
Fix file mounts (work dir change) and python reloading
2 parents c688f50 + 5c3aa29 commit 8b0f5ad

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

docker-compose.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
services:
66
vote:
7-
build: ./vote
8-
# use python rather than gunicorn for local dev
9-
command: python app.py
7+
build:
8+
context: ./vote
9+
target: dev
1010
depends_on:
1111
redis:
1212
condition: service_healthy
@@ -17,7 +17,7 @@ services:
1717
retries: 3
1818
start_period: 10s
1919
volumes:
20-
- ./vote:/app
20+
- ./vote:/usr/local/app
2121
ports:
2222
- "5000:80"
2323
networks:
@@ -32,7 +32,7 @@ services:
3232
db:
3333
condition: service_healthy
3434
volumes:
35-
- ./result:/app
35+
- ./result:/usr/local/app
3636
ports:
3737
- "5001:80"
3838
- "127.0.0.1:9229:9229"

vote/Dockerfile

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# Using official python runtime base image
2-
FROM python:3.11-slim
1+
# Define a base stage that uses the official python runtime base image
2+
FROM python:3.11-slim AS base
33

4-
# add curl for healthcheck
4+
# Add curl for healthcheck
55
RUN apt-get update && \
66
apt-get install -y --no-install-recommends curl && \
77
rm -rf /var/lib/apt/lists/*
@@ -13,6 +13,16 @@ WORKDIR /usr/local/app
1313
COPY requirements.txt ./requirements.txt
1414
RUN pip install --no-cache-dir -r requirements.txt
1515

16+
# Define a stage specifically for development, where it'll watch for
17+
# filesystem changes
18+
FROM base AS dev
19+
RUN pip install watchdog
20+
ENV FLASK_ENV=development
21+
CMD ["python", "app.py"]
22+
23+
# Define the final stage that will bundle the application for production
24+
FROM base AS final
25+
1626
# Copy our code from the current folder to the working directory inside the container
1727
COPY . .
1828

0 commit comments

Comments
 (0)