{"id":18613536,"url":"https://github.com/kyzima-spb/docker-flask","last_synced_at":"2026-04-12T13:47:47.375Z","repository":{"id":83123440,"uuid":"284128368","full_name":"kyzima-spb/docker-flask","owner":"kyzima-spb","description":"Base image to run Flask application in docker container.","archived":false,"fork":false,"pushed_at":"2024-06-17T12:20:41.000Z","size":58,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-27T02:24:57.075Z","etag":null,"topics":["docker","flask","python","web"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kyzima-spb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-07-31T20:58:50.000Z","updated_at":"2023-04-25T13:26:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"d337c592-9468-4da9-a1e5-bef75bfa195a","html_url":"https://github.com/kyzima-spb/docker-flask","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kyzima-spb%2Fdocker-flask","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kyzima-spb%2Fdocker-flask/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kyzima-spb%2Fdocker-flask/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kyzima-spb%2Fdocker-flask/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kyzima-spb","download_url":"https://codeload.github.com/kyzima-spb/docker-flask/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239406440,"owners_count":19633024,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","flask","python","web"],"created_at":"2024-11-07T03:22:40.399Z","updated_at":"2025-11-03T02:30:24.446Z","avatar_url":"https://github.com/kyzima-spb.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Table of contents\n\n`kyzimaspb/flask` - is the base image for creating your own image with the Flask application.\n\n- [How to create an image?](#how-to-create-an-image)\n  - [Directory organization](#directory-organization) \n  - [Create Dockerfile](#create-dockerfile)\n  - [Run in production mode](#run-in-production-mode)\n  - [Run in development mode](#run-in-development-mode)\n- [How to change UID/GID?](#how-to-change-uidgid)\n- [Gunicorn configuration](#gunicorn-configuration)\n  - [Method 1: Environment Variables](#method-1--environment-variables)\n  - [Method 2: Configuration file](#method-2--configuration-file)\n\n\n## How to create an image?\n\n### Directory organization\n\nLet's look at an example of creating an image for an existing Flask application.\n\nThe Flask application will use the project's [flat-layout][1] directory organization technique:\n\n```\nproject_root_directory\n├── Dockerfile        # To build an image\n├── pyproject.toml    # AND/OR setup.cfg, setup.py\n├── requirements.txt  # Fixed dependencies\n├── ...\n├── instance          # Configuration or deployment-specific files\n└── app\n    ├── ...\n    └── __init__.py   # Contains the app variable or factory\n```\n\n### Create Dockerfile\n\nIt is recommended that you fix the version of the base image.\nThe version used is just an example:\n\n```dockerfile\nFROM kyzimaspb/flask:3.9-slim-bullseye\n\nCOPY ./requirements.txt ./\n\nRUN set -ex \\\n    \u0026\u0026 pip install \\\n        --no-cache-dir \\\n        --disable-pip-version-check \\\n        -r requirements.txt\n\nCOPY . ./\n```\n\n### Run in production mode\n\nBuild an image file named `flask_app`\nthen run the container named `flask_app_1` in daemon mode\nand forward the specified ports\nto the specified ports of the host machine:\n\n```shell\n$ docker build -t flask_app .\n$ docker run \\\n      --rm \\\n      -d \\\n      --name flask_app_1 \\\n      -p 5000:5000 \\\n      -e FLASK_APP=app:app \\\n      flask_app\n```\n\nGunicorn is used as a production UWSGI web server.\n\n### Run in development mode\n\nIn development mode, the application's source files are mounted into the container as a volume.\n\nBuild an image file named `flask_app` then run the container named `flask_app_1`:\n\n```bash\n$ docker build -t flask_app .\n$ docker run \\\n    --rm \\\n    -ti \\\n    --name flask_app_1 \\\n    -v $(pwd):/app \\\n    -e FLASK_APP=app:app \\\n    -e FLASK_DEBUG=1 \\\n    flask_app\n```\n\nIn Flask below version 2.2.0, the `FLASK_ENV` environment variable is used to enable debug mode:\n\n```bash\n$ docker run \\\n    --rm \\\n    -ti \\\n    --name flask_app_1 \\\n    -v $(pwd):/app \\\n    -e FLASK_APP=app:app \\\n    -e FLASK_ENV=development \\\n    flask_app\n```\n\n\n## How to change UID/GID?\n\nBy default, the application runs as a normal user with id 1000.\nYou can specify any user or group id\nvia the `USER_ID` and `GROUP_ID` environment variables at startup:\n\n```shell\n$ docker run \\\n      --rm \\\n      -d \\\n      --name flask_app_1 \\\n      -p 5000:5000 \\\n      -e FLASK_APP=app:app \\\n      -e USER_UID=1001 \\\n      -e USER_GID=1001 \\\n      flask_app\n```\n\nYou can also use existing user or group names:\n\n```shell\n$ docker run \\\n      --rm \\\n      -d \\\n      --name flask_app_1 \\\n      -p 5000:5000 \\\n      -e FLASK_APP=app:app \\\n      -e USER_UID=www-data \\\n      -e USER_GID=www-data \\\n      flask_app\n```\n\n\n## Gunicorn configuration\n\nBy default, Gunicorn stores configuration files in the `/etc/gunicorn` directory,\nbut it can be changed using the `GUNICORN_CONFIG_LOCATION` environment variable.\n\n### Method 1: Environment Variables\n\nConfiguration parameter values can be set via environment variables with the `GUNICORN_` prefix in the variable name.\n\nThe parameter names are the same as the environment variable names.\nFor example, the value of the `timeout` option can be set using the `GUNICORN_TIMEOUT` environment variable.\n\nAn exception for the `bind` option, its value is given by two variables: `GUNICORN_HOST` and `GUNICORN_PORT`.\n\n```shell\n$ docker run \\\n      --rm \\\n      -d \\\n      --name flask_app_1 \\\n      -p 9000:9000 \\\n      -e FLASK_APP=app:app \\\n      -e GUNICORN_PORT=9000 \\\n      -e GUNICORN_TIMEOUT=5000 \\\n      flask_app\n```\n\nSo far, a limited number of variables are supported to test this approach.\n\n### Method 2: Configuration file\n\nIf you don't like the first method for some reason,\nyou can copy the config file into the image:\n\n```dockerfile\n# ...\nCOPY ./gunicorn_config.py /etc/gunicorn/config.py\n# ...\n```\n\nOr mount the file to the container at startup:\n\n```shell\n$ docker run \\\n      --rm \\\n      -d \\\n      --name flask_app_1 \\\n      -p 5000:5000 \\\n      -e FLASK_APP=app:app \\\n      -v $(pwd)/gunicorn_config.py:/etc/gunicorn/config.py \\\n      flask_app\n```\n\n\n[1]: \u003chttps://setuptools.pypa.io/en/latest/userguide/package_discovery.html#flat-layout\u003e \"flat-layout\"\n[2]: \u003chttps://setuptools.pypa.io/en/latest/userguide/package_discovery.html#src-layout\u003e \"src-layout\"\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkyzima-spb%2Fdocker-flask","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkyzima-spb%2Fdocker-flask","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkyzima-spb%2Fdocker-flask/lists"}