Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 14 additions & 34 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,40 +1,20 @@
# Install the base requirements for the app.
# This stage is to support development.
FROM --platform=$BUILDPLATFORM python:alpine AS base
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
# Use lightweight Python base image
FROM python:3.11-alpine

FROM --platform=$BUILDPLATFORM node:18-alpine AS app-base
# Set working directory
WORKDIR /app
COPY app/package.json app/yarn.lock ./
COPY app/spec ./spec
COPY app/src ./src

# Run tests to validate app
FROM app-base AS test
RUN yarn install
RUN yarn test

# Clear out the node_modules and create the zip
FROM app-base AS app-zip-creator
COPY --from=test /app/package.json /app/yarn.lock ./
COPY app/spec ./spec
COPY app/src ./src
RUN apk add zip && \
zip -r /app.zip /app

# Dev-ready container - actual files will be mounted in
FROM --platform=$BUILDPLATFORM base AS dev
CMD ["mkdocs", "serve", "-a", "0.0.0.0:8000"]
# Copy requirements and install dependencies
COPY requirements.txt .
RUN apk add --no-cache build-base libffi-dev openssl-dev
RUN pip install --upgrade pip
RUN pip install -r requirements.txt

# Do the actual build of the mkdocs site
FROM --platform=$BUILDPLATFORM base AS build
# Copy all other project files
COPY . .
RUN mkdocs build

# Extract the static content from the build
# and use a nginx image to serve the content
FROM --platform=$TARGETPLATFORM nginx:alpine
COPY --from=app-zip-creator /app.zip /usr/share/nginx/html/assets/app.zip
COPY --from=build /app/site /usr/share/nginx/html
# Expose app port
EXPOSE 3000

# Run the app
CMD ["python", "app.py"]
40 changes: 40 additions & 0 deletions Dockerfile.orig
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@



# Install the base requirements for the app
# This stage supports development
FROM python:3.11-alpine AS base

# Install system dependencies required for building Python packages
RUN apk add --no-cache build-base libffi-dev openssl-dev

WORKDIR /app
COPY requirements.txt .
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
FROM app-base AS test
RUN yarn install
RUN yarn test

# Clear out the node_modules and create the zip
FROM app-base AS app-zip-creator
COPY --from=test /app/package.json /app/yarn.lock ./
COPY app/spec ./spec
COPY app/src ./src
RUN apk add zip && \
zip -r /app.zip /app

# Dev-ready container - actual files will be mounted in
FROM --platform=$BUILDPLATFORM base AS dev
CMD ["mkdocs", "serve", "-a", "0.0.0.0:8000"]

# Do the actual build of the mkdocs site
FROM --platform=$BUILDPLATFORM base AS build
COPY . .
RUN mkdocs build

# Extract the static content from the build
# and use a nginx image to serve the content
FROM --platform=$TARGETPLATFORM nginx:alpine
COPY --from=app-zip-creator /app.zip /usr/share/nginx/html/assets/app.zip
COPY --from=build /app/site /usr/share/nginx/html
47 changes: 13 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,23 @@
# Docker Getting Started Tutorial
# Docker Flask Setup

This tutorial was written with the intent of helping folks get up and running
with containers and is designed to work with Docker Desktop. While not going too much
into depth, it covers the following topics:
A minimal Flask app containerized with Docker.
This repository demonstrates how to build and run a small Flask app inside a Docker container — useful for quick local testing and learning Docker.

- Running your first container
- Building containers
- Learning what containers are
- Running and removing containers
- Using volumes to persist data
- Using bind mounts to support development
- Using container networking to support multi-container applications
- Using Docker Compose to simplify the definition and sharing of applications
- Using image layer caching to speed up builds and reduce push/pull size
- Using multi-stage builds to separate build-time and runtime dependencies
---

## Getting Started
## 🧰 Contents
- `Dockerfile` — simple Dockerfile using `python:3.11-alpine`
- `app.py` — minimal Flask app
- `requirements.txt` — Python packages (Flask)

If you wish to run the tutorial, you can use the following command after installing Docker Desktop:
---

```bash
docker run -d -p 80:80 docker/getting-started
```

Once it has started, you can open your browser to [http://localhost](http://localhost).

## Development

This project has a `docker-compose.yml` file, which will start the mkdocs application on your
local machine and help you see changes instantly.
## 🚀 Quickstart (build & run)

### 1️⃣ Build the image
```bash
docker compose up
```
docker build -t getting-started:flask .

## Contributing

If you find typos or other issues with the tutorial, feel free to create a PR and suggest fixes!
docker run -d -p 3000:3000 --name getting-started getting-started:flask

If you have ideas on how to make the tutorial better or want to suggest adding new content, please open an
issue first before working on your idea. While we love input, we want to keep the tutorial scoped to new-comers.
As such, we may reject ideas for more advanced requests and don't want you to lose any work you might
have done. So, ask first and we'll gladly hear your thoughts!
10 changes: 10 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from flask import Flask
app = Flask(__name__)

@app.route('/')
def home():
return "✅ Docker Flask App is Running Successfully!"

if __name__ == '__main__':
# Make sure it listens on all interfaces so Docker can expose it
app.run(host='0.0.0.0', port=3000, debug=True)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ mkdocs-material==4.6.3
mkdocs-minify-plugin==0.2.3
pygments==2.7.4
pymdown-extensions==7.0
flask