Yes, it is possible to use Docker for that.

The Dockerfile would look like this:

FROM ubuntu
MAINTAINER xxx <[email protected]>

# update ubuntu repository
RUN DEBIAN_FRONTEND=noninteractive apt-get -y update

# install ubuntu packages
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install python python-pip

# install python requirements
RUN pip install ...

# define a mount point
VOLUME /student.py

# define command for this image
CMD ["python","/student.py"]

Now, you have to build this image with docker build -t student_test ..

To start the script and grab the output you can use:

docker run --volume /path/to/s12345.py:/student.py student_test > student_results_12345.txt`.

The --volume parameter is needed, to mount a student script to the defined mount point. Also, you could start multiple containers at once.

All paths are relative to current working directory.

Answer from svenwltr on Stack Overflow
🌐
CircleCI
circleci.com › blog › automating-deployment-dockerized-python-app
Dockerize a Python app and deploy to Docker Hub - CircleCI
July 1, 2024 - In this tutorial, you will learn how Docker frees developers from setup problems and port clashes. First, you will learn how to “Dockerize” a sample Python application using a custom Dockerfile. Then you will create a CI/CD pipeline to automatically build and test your Docker image every time you update the underlying code.
🌐
Medium
medium.com › @shuklashubh818 › exploring-docker-py-a-python-library-for-docker-automation-8df5bc727fbe
Exploring Docker-Py: A Python Library for Docker Automation | by Shubh Prakash Shukla | Medium
February 15, 2024 - Docker-Py empowers Python developers ... interface. By leveraging Docker-Py, developers can automate Docker-related tasks, build scalable and resilient applications, and streamline their Docker workflows with ease....
🌐
OneUptime
oneuptime.com › home › blog › how to use python docker sdk (docker-py) for automation
How to Use Python Docker SDK (docker-py) for Automation
February 8, 2026 - Use the Python Docker SDK (docker-py) to automate container management, image builds, and orchestration tasks programmatically.
🌐
The Null Route
blog.dchidell.com › 2017 › 01 › 19 › automating-docker-with-python
Automating Docker with Python - The Null Route
March 30, 2018 - Here's something I threw together today mainly because I could, but this script tests the docker engine on a host by downloading the alpine nginx container, running 1000 instances of it, making a HTTP request to each container and confirming each instance is online. Then destroys all the containers and exits. This took a while to run for me, and consumed about 10GB of RAM. Don't do it on a production system! #!/usr/bin/python3 import docker import requests def main(): # Connect to the default unix socket (/var/run/docker.sock) client = docker.from_env() #Pull the nginx:alpine image client.images.pull('nginx:alpine') #Define some test parameters, our first HTTP port and the number of containers portstart = 10000 count = 1000 #Create and start 'count' number of containers.
🌐
DEV Community
dev.to › vvakim › automating-my-docker-apache-server-with-python-2mo3
Automating My Docker Apache Server with Python - DEV Community
May 15, 2025 - Local environment confusion – Mixing Docker CLI and Python SDK sometimes caused conflicts. Staying consistent with the SDK helped. This updated project now covers the full lifecycle of a Docker container—from image build to deployment—with no manual CLI steps required. If you're learning Docker, automating your workflow with Python is a great way to cement your understanding while leveling up your DevOps toolkit.
Find elsewhere
🌐
Simplilearn
simplilearn.com › home › resources › software development › how to run a python script using docker: all you need to know
What Is Docker Python: How to Create and Run it? | Simplilearn
November 18, 2025 - Learn how Docker Python is used for automating the deployment of any application inside a software container. Read on to know how to create and run it.
Address   5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
Docker
docker.com › blog › how-to-dockerize-your-python-applications
How to “Dockerize” Your Python Applications | Docker
Entering the docker compose upcommand will automatically prompt your containers to grab any .env values and substitute them. This allows for active configuration changes. You must install any third-party libraries for them to work properly. Enter the following command to do so, using our earlier libraries: RUN pip install requests beautifulsoup4 python-dotenv
Published   November 6, 2024
🌐
Visual Studio Code
code.visualstudio.com › docs › containers › quickstart-python
Python in a container
November 3, 2021 - Build, run, and verify the functionality of a Django, Flask, or General Python app. Debug the app running in a container. Install Docker on your machine and add it to the system path.
🌐
Developers Heaven
developers-heaven.net › home › automating docker workflows with the python sdk
Automating Docker Workflows with the Python SDK - Developers Heaven
July 13, 2025 - Forget manual Dockerfile execution; now you can define and execute image builds directly from your Python scripts. Defining Image Build Parameters: Control build context, Dockerfile location, and build arguments programmatically. Utilizing the Docker API: Leverage the client.images.build() method for initiating image builds. Handling Build Output: Stream and process build logs in real-time for monitoring and error handling. Tagging Images: Automatically tag built images with version numbers or other relevant identifiers.
🌐
Medium
medium.com › @d.dandapat96 › comprehensive-guide-running-your-python-pytest-automation-framework-with-docker-254610d56a55
Comprehensive Guide: Running Your Python Pytest Automation Framework with Docker | by Dipankar Dandapat | Medium
November 29, 2025 - Before we begin, ensure you have Docker Desktop installed and running on your machine. Your Python project should have its dependencies defined in a requirements.txt file. A well-organized project structure is crucial for maintainability. Here is a recommended layout: my-automation-project/ ├── tests/ │ └── test_example.py ├── reports/ │ ├── allure-results/ (This will be generated during the run) │ └── allure-report/ (This will be generated after the run) ├── .dockerignore ├── docker-compose.yml ├── Dockerfile ├── entrypoint.sh (Optional but recommended for parameterization) └── requirements.txt
🌐
Docker
docs.docker.com › guides › python
Python | Docker Docs
Python Docker Hardened Images · 20 minutes · 1 · Containerize your app · 2 · Develop your app · 3 · Linting and typing · 4 · Automate your builds with GitHub Actions · 5 · Test your deployment« Back to all guides · This guide explains how to containerize Python applications using Docker.
🌐
Dojo Five
dojofive.com › home › testing python scripts in a docker container
Testing Python Scripts in A Docker Container - Dojo Five - Modern Embedded Firmware Development
April 25, 2025 - # To run the script directly % docker run --rm -v $(pwd)/src:/src -v $(pwd)/helpers:/helpers python-in-docker:latest python /src/hello.py · The containerized Python script could be run automatically as a part of a Continuous Integration pipeline, further easing the manual burden of testing that our ever-growing repository of scripts are behaving as we expect.
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-run-a-python-script-using-docker
How to Run a Python Script using Docker? - GeeksforGeeks
May 3, 2025 - Inside the dockerfile we will start by first taking the python base image from docker hub. A tag latest is used to get the latest official python image. It is very important to set your working directory inside your container.
🌐
Medium
medium.com › @brentchav › how-to-automate-tasks-with-airflow-docker-and-python-on-your-local-machine-1aa5b928da23
How to Automate tasks with Airflow, Docker, and Python on your Local Machine | by Breno Teixeira | Medium
January 21, 2025 - In this article, we explored a comprehensive example of leveraging the power of Docker, Apache Airflow, and Python to automate tasks. I hope this was helpful to you.
🌐
Medium
nschdr.medium.com › running-scheduled-python-tasks-in-a-docker-container-bf9ea2e8a66c
Running scheduled Python tasks in a Docker container | by Nils Schröder | Medium
February 12, 2021 - AUTOMATE YOUR LIFE Running scheduled Python tasks in a Docker container A boilerplate project for running a Python script in a Docker container using crontab. Including email alerts. Python is really …
🌐
GitHub
github.com › heyamay › Docker-Sharepoint-Automation
GitHub - heyamay/Docker-Sharepoint-Automation: A Python CLI to pull Docker images, save as .tar, and move to a OneDrive-synced "hot folder" for automatic, secure upload to SharePoint, bypassing complex authentication.
This Python-based command-line tool automates the process of pulling Docker images from a public registry, saving them as .tar files, and preparing them for upload to a SharePoint document library.
Author   heyamay
🌐
Technoligent
technoligent.com › home › python › automating devops pipelines with python and docker: a complete guide
Automating DevOps Pipelines with Python and Docker: A Complete Guide - Technoligent
December 19, 2024 - GitHub Actions: Include Python Docker scripts in workflows using actions/setup-python. Automate container builds, tests, and deployments based on code changes or scheduled triggers.