Ship a Flask Capstone App with Docker and Docker Compose in Python | 100 Days of Python — Day 95
How do you deploy a Python app with Docker? You build Docker Deploy, writing one Dockerfile and one compose file so your portfolio app runs the same on any machine. Day 95 of 100 Days of Python — a hands-on, step-by-step lesson with Instructor: Moon. No experience needed. You will learn: Dockerfile — The recipe for your app docker-compose.yml — App plus database, one command docker compose up — Build it. Run it. Done. Final project: Docker Deploy. Example output: Wrote Dockerfile Code from this lesson (main.py): ``` DOCKERFILE = """FROM python:3.12-slim WORKDIR /app COPY requirements.txt . RUN pip install -r requirements.txt COPY . . CMD ["flask", "run", "--host=0.0.0.0"] """ COMPOSE = """services: web: build: . ports: "5000:5000" volumes: ./data:/app/data """ open("Dockerfile", "w").write(DOCKERFILE) open("docker-compose.yml", "w").write(COMPOSE) open("requirements.txt", "w").write("flask\nflask-sqlalchemy\n") open(".dockerignore", "w").write("__pycache__\n*.db\n") print("Wrote Dockerfile") print("Wrote docker-compose.yml") print("Wrote requirements.txt") print("Wrote .dockerignore") print("Run: docker compose up --build") ``` Quiz: 1. What does a Dockerfile describe? — the recipe: base image, files, installs, and the command that runs the app 2. Why bind Flask to 0.0.0.0 in a container? — so the app listens on all interfaces and the mapped port is reachable from outside 3. What does docker compose up --build do? — it builds the image and starts every service in docker-compose.yml Where this is heading: Deployment is what makes a portfolio real — anyone can run your app with one command, and that is what you demo in an interview. Next: Day 96: interview prep — presenting your capstone like a hire. Chapters: 0:00 Hook — hook 1:22 Setup — setup 2:06 Step 1 — step1 3:53 Debugging — debug 5:12 Step 2 — step2 6:48 Project — Docker Deploy — project 9:13 Summary — outro
Название:
Ship a Flask Capstone App with Docker and Docker Compose in Python | 100 Days of Python — Day 95
Категория:
Разное