๐ŸŒ
Docker
docker-py.readthedocs.io
Docker SDK for Python - Read the Docs
A Python library for the Docker Engine API. It lets you do anything the docker command does, but from within Python apps โ€“ run containers, manage containers, manage Swarms, etc. For more information about the Engine API, see its documentation.
๐ŸŒ
GitHub
github.com โ€บ docker โ€บ docker-py
GitHub - docker/docker-py: A Python library for the Docker Engine API ยท GitHub
A Python library for the Docker Engine API. Contribute to docker/docker-py development by creating an account on GitHub.
Starred by 7.2K users
Forked by 1.7K users
Languages ย  Python
Discussions

Dockerizing an API built with python on local machine - Stack Overflow
I have cloned a repository of an API built with python on my local machine and my goal is to be able to send requests and receive responses locally. I'm not familiar python but the code is very rea... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Hosting a Docker web app with a Python API
If your budget can stretch to ~$5/month, you could try pythonanywhere? It's obviously not 'self-hosted' though. Otherwise, host the app in a docker container or virtual machine and open up a/the port that others can use to access the app at the host's IP address. If you're at a research institute/university however, the IT/InfoSec department might have something to say about this if they've already said no to you before though. More on reddit.com
๐ŸŒ r/selfhosted
7
4
October 3, 2024
python with bloomberg API

Bloomberg has published this library and documentation, and I noticed lots of examples in the git repo.

https://www.bloomberg.com/professional/support/api-library/

This directory contains an interface for interacting with Bloomberg API services using the Python programming language.

https://github.com/msitt/blpapi-python

More on reddit.com
๐ŸŒ r/learnpython
6
4
September 10, 2018
Communicate with Docker containers via API
offer wine compare retire market cough nutty angle trees thumb This post was mass deleted and anonymized with Redact More on reddit.com
๐ŸŒ r/docker
9
5
January 22, 2023
๐ŸŒ
Docker
docker-py.readthedocs.io โ€บ en โ€บ stable โ€บ api.html
Low-level API โ€” Docker SDK for Python 7.1.0 documentation
Similar to the docker save command. ... chunk_size (int) โ€“ The number of bytes returned by each iteration of the generator. If None, data will be streamed as it is received. Default: 2 MB ... A stream of raw archive data. ... >>> image = client.api.get_image("busybox:latest") >>> f = open('/tmp/busybox-latest.tar', 'wb') >>> for chunk in image: >>> f.write(chunk) >>> f.close()
๐ŸŒ
MetricFire
metricfire.com โ€บ blog โ€บ develop-and-deploy-a-python-api-with-kubernetes-and-docker
Comprehensive Guide to Developing and Deploying a Python API with Docker and Kubernetes (Part I) | MetricFire
May 14, 2025 - In this tutorial, we use Docker to containerize an app, then run it on development environments using Docker Compose. We'll use a Python API as our main app.
๐ŸŒ
Docker Docs
docs.docker.com โ€บ reference โ€บ docker engine api โ€บ sdk โ€บ examples
Examples using the Docker Engine SDKs and Docker API
Examples on how to perform a given Docker operation using the Go and Python SDKs and the HTTP API using curl.
๐ŸŒ
Docker Docs
docs.docker.com โ€บ reference โ€บ samples โ€บ python samples
Python samples | Docker Docs
Docker Samples: A collection of over 30 repositories that offer sample containerized demo applications, tutorials, and labs.
๐ŸŒ
Docker
docker-py.readthedocs.io โ€บ en โ€บ stable
Docker SDK for Python โ€” Docker SDK for Python 7.1.0 documentation
A Python library for the Docker Engine API. It lets you do anything the docker command does, but from within Python apps โ€“ run containers, manage containers, manage Swarms, etc. For more information about the Engine API, see its documentation.
๐ŸŒ
Ben Postance
bpostance.github.io โ€บ posts โ€บ docker-fask-api
How to containerize a simple Rest API using Python Flask | Ben Postance
April 19, 2021 - See these instructions for Ubunut/Linux Mint 19 installation. Create an account, download and install Docker Desktop for your operating system following the official channel. Once installed you check some basics using the following commands. See the git repo readme and official docs for more.
Find elsewhere
๐ŸŒ
Josefjebavy
blog.josefjebavy.cz โ€บ en โ€บ programming โ€บ docker-api-python
Python program to control Docker using the API
April 3, 2024 - Python library documentation for controlling docker using the API: https://docker-py.readthedocs.io/en/stable/
๐ŸŒ
FastAPI
fastapi.tiangolo.com โ€บ deployment โ€บ docker
FastAPI in Containers - Docker - FastAPI
You will see the alternative automatic documentation (provided by ReDoc): If your FastAPI is a single file, for example, main.py without an ./app directory, your file structure could look like this: . โ”œโ”€โ”€ Dockerfile โ”œโ”€โ”€ main.py โ””โ”€โ”€ requirements.txt ยท Then you would just have to change the corresponding paths to copy the file inside the Dockerfile: FROM python:3.14 WORKDIR /code COPY ./requirements.txt /code/requirements.txt RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt # (1)!
๐ŸŒ
Docker
docs.docker.com โ€บ guides โ€บ python
Python | Docker Docs
This guide is a community contribution. Docker would like to thank Esteban Maya and Igor Aleksandrov for their contribution to this guide. The Python language-specific guide teaches you how to containerize a Python application using Docker.
Top answer
1 of 1
1

Adjust Dockerfile

Assuming all code is in the /app directory you have already copied over all your code and installed all the dependencies required for the application.

But you are missing - at least (see disclaimer) - one essential line in the Dockerfile which is actually the most important line as it is the CMD command to tell Docker which command/ process should be executed when the container starts.

I am not familiar with the particular base image you are using (which is defined using the FROM command) but after googling I found this repo which suggests the following line, which does make a lot of sense to me as it starts a web server:

# open port 80 on the container to make it accesable from the outside
EXPOSE 80
# line as described in repo to start the web server
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]

This should start the web server on port 80 using the application stored in a variable app in your main.py when the container starts.

Build and run container

When you have added that you need to build your image using docker build command.

docker build -t asmoun/my-container .

This builds an container image asmoun/my-container using the Dockerfile in the current directory, hence the .. So make sure you execute that when in the directory with the Dockerfile. This will take some time as the base image has to download and dependencies need to be installed.

You now have an image that you can run using docker run command:

docker run --name my-fastapi-container -d -p 80:80 asmoun/my-container

This will start a container called my-fastapi-container using the image asmoun/my-container in detached mode (-d option that makes sure your TTY is not attached to the container) and define a port mapping, which maps the port 80 on the host to port 80 on the container, which we have previously exposed in the Dockerfile (EXPOSE 80).

You should now see some ID getting printed to your console. This means the container has started. You can check its state using docker ps -a and you should see it marked as running. If it is, you should be able to connect to localhost:80 now. If it is not use docker logs my-fastapi-container to view the logs of the container and you'll hopefully learn more.

Disclaimer

Please be aware that this is only a minimal guide on how you should be able to get a simple FastAPI container up and running, but some parameters could well be different depending on the application (e.g. name of main.py could be server.py or similar stuff) in which case you will need to adjust some of the parameters but the overall process (1. adjust Dockerfile, 2. build container, 3. run container) should work. It's also possible that your application expects some other stuff to be present in the container which would need to be defined in the Dockerfile but neither me, nor you (presumably) know this, as the Dockerfile provided seems to be incomplete. This is just a best effort answer.

I have tried to link all relevant resources and commands so you can have a look at what some of them do and which options/ parameters might be of interest for you.

๐ŸŒ
DEV Community
dev.to โ€บ francescoxx โ€บ python-fullstack-rest-api-app-with-docker-1101
Python ๐Ÿ fullstack REST API app with Docker ๐Ÿณ - DEV Community
January 6, 2024 - The backend is written in Python, using Flask and SQLAlchemy. The database is PostgreSQL. We will use Docker to run the database, the backend, and also the frontend (you can also use Vercel). We will use Docker Compose to run the frontend, the backend, and the database together. Basic knowledge of what is a frontend, a backend, an API, and a database
๐ŸŒ
Visual Studio Code
code.visualstudio.com โ€บ docs โ€บ containers โ€บ quickstart-python
Python in a container
November 3, 2021 - For more information about setting and using environment variables in the Dockerfile, see the ENV instruction and Environment replacement section in the Docker documentation. To give Python web developers a great starting point, we chose to use Gunicorn as the default web server.
๐ŸŒ
Docker Docs
docs.docker.com โ€บ reference โ€บ docker engine api โ€บ sdk
SDK | Docker Docs
The Docker Engine API is a RESTful API accessed by an HTTP client such as wget or curl, or the HTTP library which is part of most modern programming languages. Use the following commands to install the Go or Python SDK.
๐ŸŒ
Docker
docker.com โ€บ blog โ€บ how-to-dockerize-your-python-applications
How to โ€œDockerizeโ€ Your Python Applications | Docker
The Docker SDK for Python is another useful way to run docker commands within Python apps themselves. Are you a film buff whoโ€™s also eager to explore further? Check out Lorenzo Costaโ€™s tutorial on quickly deploying your own Game of Thrones API with Flask, MongoDB, and other tools.
Published ย  November 6, 2024
๐ŸŒ
PyPI
pypi.org โ€บ project โ€บ docker
docker ยท PyPI
A Python library for the Docker Engine API.
      ยป pip install docker
    
Published ย  May 23, 2024
Version ย  7.1.0
๐ŸŒ
Real Python
realpython.com โ€บ tutorials โ€บ docker
Python Docker Tutorials โ€“ Real Python
Use Docker to create reproducible environments and ship Python apps. On this page youโ€™ll find practical guides that show how to write a Dockerfile, manage dependencies, and run your code in containers on macOS, Windows, and Linux.
๐ŸŒ
CircleCI
circleci.com โ€บ blog โ€บ automating-deployment-dockerized-python-app
Dockerize a Python app and deploy to Docker Hub - CircleCI
July 1, 2024 - To demonstrate the Docker process in this section of the tutorial, you will use FastAPI RestAPI locally. The API has already been created for you. Start by cloning the repository using this command: git clone https://github.com/CIRCLECI-GWP/python-app-dockerhub.git cd python-app-dockerhub
๐ŸŒ
Docker Docs
docs.docker.com โ€บ reference โ€บ docker engine api
Docker Engine API | Docker Docs
The Docker Go SDK allows you to enable API version negotiation, automatically selects an API version that's supported by both the client and the Docker Engine that's in use. For the SDKs, you can also specify the API version programmatically as a parameter to the client object. See the Go constructor or the Python SDK documentation for client.