The Service
Explore how to create and deploy a Python service within a Docker container. Understand managing dependencies with setup.py, organizing project structure, using virtual environments, defining entry points, and configuring the Dockerfile. Gain practical knowledge of packaging and running Python applications in containerized environments.
To create the service, we are going to launch the Python application inside a Docker container. Starting from a base image, the container will have to install the dependencies for the application to run, which also has dependencies at the operating system level.
This is actually a choice because it depends on how the dependencies are used. If a package we use requires other libraries on the operating system to compile at installation time, we can avoid this simply by building a wheel for our platform of the library and installing this directly. If the libraries are needed at runtime, then there is no choice but to make them part of the image of the container.
The project structure
Now, we will discuss one of the many ways of preparing a Python application to be run inside a Docker container. This is one of the numerous alternatives for packaging a Python project into a container. First, we take a look at what the structure of the directories looks like.
The libs directory can be ignored since it's just the place where the dependencies are placed (it's displayed here to keep them in mind when they are referenced in the setup.py file, but they could be placed in a different repository and installed remotely via pip).
We have ...