What's up? this is a small project to teach myself Docker. This Docker setup works, healthchecks pass for both app and mysql, app is initialized and is listening as expected, what I'm looking is a feedback on the docker-compose and the Dockerfile parts.
FROM python:3-alpine3.16
ENV FLASK_APP=app
ENV FLASK_ENV=development
# The EXPOSE instruction indicates the ports on which a container
# will listen for connections
EXPOSE 8080
# Sets the working directory for following COPY and CMD instructions
# Notice we haven’t created a directory by this name - this instruction
# creates a directory with this name if it doesn’t exist
WORKDIR /app
# Update Python
RUN python3 -m pip install --upgrade pip setuptools wheel; \
apk add --no-cache curl
# Install any needed packages specified in requirements.txt
COPY ./app/requirements.txt /app/requirements.txt
RUN pip install --no-cache-dir -r /app/requirements.txt
COPY ./app/app.py /app/app.py
# the INTERNAL port of the app, inside the container
ENV INTERNAL_APP_PORT=8080
HEALTHCHECK --timeout=2s CMD curl --fail http://localhost:${INTERNAL_APP_PORT}/health || exit 1
ENTRYPOINT [ "python3", "app.py" ]
version: "3.7"
services:
app:
platform: linux/amd64
build: .
links:
- db
ports:
- "${EXTERNAL_APP_PORT:-8080}:8080"
depends_on:
db:
condition: service_healthy
volumes:
- /usr/share/billing_app/:/app/in
db:
platform: linux/amd64
image: mysql:8
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: billdb
MYSQL_USER: billdb_owner
MYSQL_PASSWORD: password
volumes:
- ./db:/docker-entrypoint-initdb.d/
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
timeout: 20s
retries: 10
Thank you