Docker image bundling OpenJDK 11 with Python 3.7. Docker image: Debian 9 (Stretch) with OpenJDK 11 & Python 3.7. This Docker image is based on python:3.7.2-slim-stretch, filled with the content of debian:11.0.1-jre-slim-stretch, and enhanced with gcc, g, and maven. Jul 15, 2020 However, for Python applications, the slim variant of the official Docker Python image works well for most cases (eg. Instruction order matters for leveraging build cache. When building an image frequently, we definitely want to use the builder cache mechanism to speed up subsequent builds.
Links for python-docker
Download Source Package python-docker:
- Docker Compose Team (QA Page)
- Jason Pleau (QA Page)
- Felipe Sateler (QA Page)
- Homepage [github.com]
Python wrapper to access docker.io's control socket
This package contains oodles of routines that aid in controllingdocker.io over it's socket control, the same way the docker.ioclient controls the daemon.
This package provides Python 2 module bindings only.
Other Packages Related to python-docker
- interactive high-level object-oriented language (Python2 version)
- dep:python-backports.ssl-match-hostname (>= 3.5)
- Backport of the Python 3.5 SSL hostname checking function
- Python bindings for the docker credentials store API
- dep:python-ipaddress (>= 1.0.16)
- Backport of Python 3 ipaddress module (Python 2)
- elegant and simple HTTP library for Python2, built for human beings
- dep:python-six (>= 1.4.0)
- Python 2 and 3 compatibility library (Python 2 interface)
- WebSocket client library - Python 2.7
|Architecture||Package Size||Installed Size||Files|
|all||75.9 kB||461.0 kB||[list of files]|
“Pressure is something you feel when you don’t know what the hell you’re doing.” ― Peyton Manning
Once these tasks are completed, your headaches are not over; rather, in one sense they are just beginning. You need to think about the deployment of your application. Again here we have many aspects to consider – the operating system on which the server is hosted, the choice of web server, and how to manage the deployment of these components. This is especially true of companies that implement a “continuous integration” approach: one where changes made to the application code base are continually integrated into live production.
2. Docker for Packaging an Application
In this scenario, Docker offers a flexible and powerful solution to ease deployment woes. By making the deployment a part of the development process, many problems arising at deployment time can be caught at development. This is made possible by the ability of Docker to mock entire data center infrastrucure in a single processes. When a Dockerfile is used to build the infrastructure needed to run the application, each team member can have a virtual runtime environment for testing.
Let us now see how we can manage the deployment of a web application with the back-end in python using Docker. We have chosen to illustrate this process with Nginx as the web server.
3. Deployment Architecture
The server machine runs a version of Ubuntu as the OS. Actually, any Linux OS capable of running Docker will do.
We have configured Nginx with an SSL certificate too so that HTTPS is supported. Click here for more details on how to SSL-enable Nginx inside Docker..
See Full List On Hub.docker.com
4. The Dockerfile
We start with Ubuntu Server 16.04, and update the OS. Next a bunch of needed software is installed, including Nginx.
Next, we install the python components using pip. We also install supervisor to run both Nginx and uWSGI services.
We add a non-privileged user called aurora, and cleanup Nginx installation a bit.
We now expose the ports needed for the web: 80 and 443.
Next, we copy Nginx configuration which includes the SSL certificate and appropriate SSL directives. See this post for complete details of the SSL configuration.
Docker Debian Python Install
We also need supervisor configuration and uWSGI configuration. See below where these are explained in detail. Finally, the supervisor daemon is run in the foreground in the docker environment.
5. Configuring Nginx
We configure Nginx to redirect all requests starting with the prefix /api to uWSGI. This is done as shown below. Requests for /api are passed on to uWSGI listening on port 3031 on the localhost. Any other requests are handled by Nginx directly (the location block below).
The file uwsgi_params included in the /api location block is shown below. This configuration is required by uWSGI and is not application specific.
Supervisor is a system used to manage processes at system startup. Here we use it to start both Nginx and uWSGI since both are needed for running the system. It uses a configuration file /etc/supervisord.conf which is shown below. This file tells supervisor to run in the foreground and spawn Nginx and uWSGI.
7. Setting up uWSGI
uWSGI is a web framework for python. It manages requests to python web modules, and serves as the interface to Nginx. Using uWSGI, you can run back-end python modules with Nginx as the web server.
It is configured as shown. The process listens on the local port 3031 for requests forwarded by Nginx. The main application file is named wsgiapp.py, which can of course pull in other modules that are required. This file is located in /home/aurora/app/ directory.
8. Building and Deployment
Once all these parts are assembled, building the docker image is as simple as:
Once the build is complete, run it as follows:
- The command maps ports 80 and 443 to the host ports.
- The static files comprising the web application is mapped as a docker volume to /home/aurora/web/ which is the Nginx web root.
- The back-end application driven by uWSGI is also mounted as a docker volume at /home/aurora/app.
Once docker is running, you now have a HTTPS web server serving files and running your python application.
For test purposes, the application we have is a very simple one.
Now, go develop a more complete application while enjoying the flexibility provided by docker for deployment!
If you face any problems, let me know in the comments below.
This article outlined the steps required for hosting a web application with a python back-end inside docker. We demonstrated how to configure Nginx for SSL and using uWSGI for python. You can now use the configuration presented here as a template for your own deployment.