{"id":18977895,"url":"https://github.com/learningbyplaying/python-webservices-fastapi-dockerize","last_synced_at":"2025-02-21T08:18:41.033Z","repository":{"id":163147230,"uuid":"637599549","full_name":"learningbyplaying/python-webservices-fastapi-dockerize","owner":"learningbyplaying","description":"How to dockerize a simple FastApi application","archived":false,"fork":false,"pushed_at":"2023-05-08T02:42:28.000Z","size":2,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-01T10:13:52.965Z","etag":null,"topics":["docker","dockerized","fastapi","python"],"latest_commit_sha":null,"homepage":"","language":"Dockerfile","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/learningbyplaying.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-08T02:29:58.000Z","updated_at":"2023-05-11T21:17:21.000Z","dependencies_parsed_at":null,"dependency_job_id":"989220f8-e130-4cf3-893e-88cb6e5e1fe2","html_url":"https://github.com/learningbyplaying/python-webservices-fastapi-dockerize","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/learningbyplaying%2Fpython-webservices-fastapi-dockerize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/learningbyplaying%2Fpython-webservices-fastapi-dockerize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/learningbyplaying%2Fpython-webservices-fastapi-dockerize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/learningbyplaying%2Fpython-webservices-fastapi-dockerize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/learningbyplaying","download_url":"https://codeload.github.com/learningbyplaying/python-webservices-fastapi-dockerize/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239978184,"owners_count":19728290,"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","dockerized","fastapi","python"],"created_at":"2024-11-08T15:31:13.176Z","updated_at":"2025-02-21T08:18:41.008Z","avatar_url":"https://github.com/learningbyplaying.png","language":"Dockerfile","readme":"\n\n# Dockerized FastApi Hello World Application\n\n```\n.\n├── Dockerfile\n├── docker-compose.yml\n├── main.py\n└── requirements.txt\n```\n\n# Requirements.txt\n\nThe requirements.txt file is used to specify the Python packages that are required for the application to run. This file is used by the Dockerfile to install the necessary packages when the container is built.\n\nThe following packages are required for the FastAPI Hello World application:\n\n```\nfastapi\nuvicorn\n```\n\nThese packages can be installed using the pip package manager. The following command can be used to install the packages:\n\n```\npip install -r requirements.txt\n```\n\nThe requirements.txt file should be placed in the same directory as the main.py file. This will ensure that the packages are installed when the container is built.\n\n### main.py\n\nThis file contains the code for the FastAPI application. It is responsible for creating the API endpoints and handling the requests.\n\n```python\nfrom fastapi import FastAPI\n\napp = FastAPI()\n\n@app.get(\"/\")\ndef read_root():\n    return {\"Hello\": \"World\"}\n```\n\nThe code above creates a FastAPI application and adds a single endpoint to it. The endpoint is accessible at the root URL (`/`) and returns a JSON object with the message `{\"Hello\": \"World\"}`.\n\n### Dockerfile\n\nThe Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. It is used to create a Docker image, which is a snapshot of a container.\n\nThe Dockerfile for this FastApi Hello World application is as follows:\n\n```\nFROM python:3.7\n\nWORKDIR /app\n\nCOPY requirements.txt .\n\nRUN pip install -r requirements.txt\n\nCOPY . .\n\nEXPOSE 80\n\nCMD [\"uvicorn\", \"main:app\", \"--host\", \"0.0.0.0\", \"--port\", \"80\"]\n```\n\nThis Dockerfile will create an image based on the Python 3.7 image. It will then copy the requirements.txt file into the image, install the dependencies, copy the application files, expose port 80, and then run the application.\n\n### docker-compose.yml\n\nThe docker-compose.yml file is used to define and run multi-container Docker applications. This file is used to define the services that make up the application, the networks they belong to, and the volumes they use.\n\nThe following code is an example of a docker-compose.yml file for a FastApi Hello World application:\n\n```\nversion: '3'\n\nservices:\n  web:\n    build: .\n    ports:\n      - \"8080:8080\"\n    volumes:\n      - .:/app\n    environment:\n      - PORT=8080\n```\n\nIn this example, the `web` service is defined. This service will build the application from the current directory, map port 8080 on the host to port 8080 on the container, mount the current directory to the `/app` directory in the container, and set the `PORT` environment variable to `8080`.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flearningbyplaying%2Fpython-webservices-fastapi-dockerize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flearningbyplaying%2Fpython-webservices-fastapi-dockerize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flearningbyplaying%2Fpython-webservices-fastapi-dockerize/lists"}