Skip to content

iqra615/python-docker-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Python API with Docker

A simple Flask API containerized using Docker, returning static JSON data about a friend (name, goals, and tech stack). This project serves as a practical demonstration of containerizing a basic Python application.

βš™οΈ Requirements

Docker installed on your machine (to build and run the container).

Python 3 (Optional, for local development/testing).

πŸ“ Project Structure

This project contains the following files:

. β”œβ”€β”€ Dockerfile # Instructions for building the Docker image β”œβ”€β”€ app.py # The core Flask application that exposes the API endpoint β”œβ”€β”€ requirements.txt # Python dependencies (Flask) └── README.md # This documentation file

πŸ“ API Description

The app.py script runs a simple Flask web server on port 5000 inside the container. It exposes one root endpoint that returns the following JSON structure:

{ "name": "Alex", "goal_in_germany": "Master German and get a full-time software engineering role.", "tech_stack": ["Python", "JavaScript", "React", "Docker", "Kubernetes"] }

🐳 Building and Running the Docker Image (Recommended)

This process allows you to run the application anywhere Docker is installed without needing a Python environment.

  1. Build the Image

Run the following command in the project's root directory. The -t flag tags the image with a custom name.

docker build -t my-python-api:1.0 .

  1. Run the Container

Run the image, mapping the container's internal port (5000) to port 5000 on your host machine.

docker run -d -p 5000:5000 --name friend-api-container my-python-api:1.0

The -d flag runs the container in detached (background) mode.

The --name assigns a descriptive name to the container.

The -p 5000:5000 maps HostPort:ContainerPort.

  1. Test the API

Access the endpoint using curl or open the URL in your browser:

curl http://localhost:5000/

  1. Cleanup

To stop and remove the running container:

docker stop friend-api-container docker rm friend-api-container

🐍 Running Locally (Without Docker)

For developers who wish to debug or test the application directly:

Install Python dependencies:

pip install -r requirements.txt

Run the API:

python app.py

Test the API: Access the endpoint: http://localhost:5000/

About

Simple Flask API containerized with Docker.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published