Sign inSign up
my-python-app logo

stden/my-python-app

By stden

•Updated 1 day ago

A Python app that checks a website and queries MySQL.

Image
Languages & frameworks
Developer tools
0

1.8K

stden/my-python-app repository overview

⁠stden/my-python-app

A Python app that checks a website and queries MySQL.

⁠What you learn

  • How layer order affects the build cache: copy dependencies before source code
  • How CMD sets the default command that runs when the container starts
  • How Docker Compose starts multiple containers on a shared network
  • How a health check delays the application start until the database is ready
  • How named volumes keep database data between container restarts

⁠Contents

  • Python with Requests, Flask, NumPy, and MySQL Connector/Python
  • A sample script that checks a website and reads rows from MySQL
  • SQL files that create and fill the sample database
  • The tree command to show the directory structure

The working directory is /workspace. The default command runs python ./my-test.py. It requests https://www.google.com, then queries the user table in the database. Requests use a 15-second timeout. A failed website check stops the program before the database query.

It runs once and exits. It does not start a web server.

⁠Tags

TagMeaningPlatform
latestLatest successful main buildlinux/amd64

View tags and image digests⁠.

⁠Pull and run

docker pull stden/my-python-app:latest
docker run --rm stden/my-python-app:latest \
  python -c 'import requests, flask, numpy, mysql.connector; print("Libraries are ready.")'

To run the full example, prepare a MySQL database with the sample SQL⁠. The database must accept connections before you start the application.

In this example, a MySQL container named db is on the course-net Docker network. Set the database user and password to match your database. change-me is a placeholder.

docker run --rm --network course-net \
  -e DB_HOST=db -e DB_USER=user -e DB_PASSWORD=change-me -e DB_NAME=my_db \
  stden/my-python-app:latest

⁠Run the full course example

The repository includes a Compose file that starts MySQL, creates the sample data, waits for MySQL, and builds the Python application:

git clone https://github.com/stden/docker-gems.git
cd docker-gems
docker compose up --build --abort-on-container-exit --exit-code-from app
docker compose down

The Compose file uses example passwords. The named database volume keeps its data after docker compose down. Use a separate project and credentials for your own application.

⁠Checks and source

GitHub Actions runs the Compose example twice: first with a new volume, then with the same volume.

Dockerfile⁠ · Compose file⁠ · Docker tutorial⁠ · Build results⁠

Tag summary

Content type

Image

Digest

sha256:2c6b715c7…

Size

433.6 MB

Last updated

1 day ago

docker pull stden/my-python-app