For me the only problem in your Dockerfile is in the line RUN apt install python -y. This is erroring with Package 'python' has no installation candidate.

It is expected since python refers to version 2.x of Python wich is deprecated and no longer present in the default Ubuntu repositories.

Changing your Dockerfile to use Python version 3.x worked fine for me.

FROM ubuntu:latest

RUN apt update
RUN apt install python3 python3-pip -y
WORKDIR /Destop/DS

COPY requirement.txt ./
RUN pip3 install -r requirement.txt

COPY script2.py ./
CMD ["python3", "./script2.py"]

To test I used requirement.txt

pandas==1.5.1

and script2.py

import pandas as pd

print(pd.__version__)

With this building the docker image and running a container from it executed succesfully.

docker build -t myimage .
docker run --rm myimage
Answer from Matteo Zanoni on Stack Overflow
🌐
Docker Hub
hub.docker.com › r › ubuntu › python
ubuntu/python - Docker Image
Current Python Docker Image from Canonical⁠, based on Ubuntu. Receives security updates and rolls to newer Python or Ubuntu release.
🌐
Python⇒Speed
pythonspeed.com › articles › base-image-python-docker-images
The best Docker base image for your Python application (February 2026)
February 4, 2026 - Older versions, which you probably don’t want to start with for a new project, include RHEL 9 and Debian 12, and as mentioned soon Ubuntu 24.04 will be superseded. You can get long term security updates for older distributions, but that’s a bad idea; better to upgrade more often. They may also not have security updates for all packages, as is the case for Debian long-term support. Another alternative is Docker’s own “official” python image, which comes pre-installed with respective versions of Python (3.10, 3.11, 3.12, etc.), and has multiple variants:
🌐
Docker Hub
hub.docker.com › _ › python
python - Official Image | Docker Hub
When using this image pip install will work if a suitable built distribution is available for the Python distribution package being installed. pip install may fail when installing a Python distribution package from a source distribution. This image does not contain the Debian packages required to compile extension modules written in other languages.
🌐
GitHub
github.com › arnaudblois › python-ubuntu-image
GitHub - arnaudblois/python-ubuntu-image: A Ubuntu Docker image with the latest Python version built with optimisations
A Ubuntu Docker image with the latest Python version built with optimisations and the latest openSSL.
Starred by 12 users
Forked by 2 users
Languages   Dockerfile 54.8% | Shell 40.9% | Python 4.3% | Dockerfile 54.8% | Shell 40.9% | Python 4.3%
🌐
GitHub
github.com › matthewfeickert › Docker-Python3-Ubuntu
GitHub - matthewfeickert/Docker-Python3-Ubuntu: Dockerfile for image built off Ubuntu 20.04 containing Python 3.10 (3.6, 3.7, 3.8, 3.9) built from source · GitHub
Dockerfile for image built off Ubuntu 20.04 containing Python 3.10 (3.6, 3.7, 3.8, 3.9) built from source - matthewfeickert/Docker-Python3-Ubuntu
Starred by 118 users
Forked by 79 users
Languages   Shell 46.9% | Makefile 26.9% | Dockerfile 26.2%
Find elsewhere
🌐
Docker Hub
hub.docker.com › r › matthewfeickert › docker-python3-ubuntu
matthewfeickert/docker-python3-ubuntu - Docker Image
Dockerfile for image built off Ubuntu 20.04⁠ containing Python 3.8⁠ (Python 3.6⁠, Python 3.7⁠) built from source
🌐
Quora
quora.com › Is-there-an-Ubuntu-image-for-Docker-that-comes-with-Python-and-pip-already-installed
Is there an Ubuntu image for Docker that comes with Python and pip already installed? - Quora
Answer (1 of 3): Yes, go to docker hub and search “python”. You will get this: https://hub.docker.com/_/python/ BTW, why do you want Ubuntu? Alpine is just fine
🌐
GitHub
gist.github.com › source-nerd › e4037755b2e76f8d8346c01548930e95
Docker Image for Ubuntu 18.04 and Python 3.6 · GitHub
Docker Image for Ubuntu 18.04 and Python 3.6. GitHub Gist: instantly share code, notes, and snippets.
🌐
Medium
medium.com › @prateek.mehra › installing-python-3-9-in-ubuntu-22-04-docker-image-194f9c9f9725
Installing Python 3.9 in Ubuntu 22.04 docker image | by Prateek Mehra | Medium
July 2, 2024 - Installing Python 3.9 in Ubuntu 22.04 docker image The Problem On trying to install Python 3.9 in a fresh ubuntu 22.04 docker image, using the following command: apt-get install -y python3.9 The …
🌐
GitHub
github.com › rcarmo › ubuntu-python
GitHub - rcarmo/ubuntu-python: A base Docker container for running Python apps with an Ubuntu userland · GitHub
This image runs the python command on docker run. You can either specify your own command, e.g: docker run --rm -ti rcarmo/ubuntu-python python hello.py
Starred by 14 users
Forked by 4 users
Languages   Makefile 59.7% | Dockerfile 40.3%
Top answer
1 of 2
7

You can read about the python image in its documentation

The interesting part is:

This tag is based off of buildpack-deps. buildpack-deps is designed for the average user of docker who has many images on their system. It, by design, has a large number of extremely common Debian packages.

And buildpack-deps itself can be based on either Debian, or Ubuntu image.

As they mention in the documentation - if you don't have specific requirements, or don't know why you'd not use another image, then python is a good choice.

In the future, you may be interested in other images if you for example want to have your deployment image smaller than the one testing with (which may have some extra tools). Or in general you could be tempted to use the smallest size possible to remove unnecessary utilities. There are reasons to do each of these - you'll likely figure out yourself at what point these matter to you.

2 of 2
3

Well, as viraptor says, Python is a good choice, but it weighs 900 MB

The size of the Python image - why 900MB?

https://github.com/docker-library/python/issues/30

There is a great blog post about the size of the docker images (in fact only the Python docker images) by Yasser Martinez

http://yasermartinez.com/blog/posts/creating-super-small-docker-images.html

Extract

Python itself is not small, a typical python installation needs close to 100 MB once uncompressed on the disk. Of course one could imagine that here are many files included that aren't needed in most of the usual cases (like the turtle module). Is it possible to create a smaller python docker image? The answer is YES; if you now do a docker pull elyase/staticpython you will get a working python image with only 8.5 MB in size.

See also the github of João Ferreira Loff

https://github.com/jfloff/alpine-python

Extract

REPOSITORY TAG SIZE jfloff/alpine-python 2.7-slim 52.86 MB python 2.7-slim 180.8 MB

jfloff/alpine-python 2.7 234.2 MB python 2.7 676.2 MB

jfloff/alpine-python 3.4-slim 110.4 MB python 3.4-slim 193.9 MB

jfloff/alpine-python 3.4 280 MB python 3.4 681.5 MB

jfloff/alpine-python latest 248.8 MB python 3.5 685.4 MB

jfloff/alpine-python latest-slim 79.11 MB python 3.5-slim 197.8 MB

🌐
GitHub
github.com › canonical › base-2204-python38
GitHub - canonical/base-2204-python38: Python 3.8 image based on ubuntu 22.04 (with scans and tests) · GitHub
Thanks to the use of latest LTS ... The image is currently published here You can use this image seamlesly as any other python Docker image by specifying it as a base with....
Author   canonical
🌐
DEV Community
dev.to › mattcale › dockerfile-for-a-python-playground-on-ubuntu-4d69
Dockerfile For A Python Playground On Ubuntu - DEV Community
September 9, 2021 - Open the Dockerfile in a text editor (use VSCode if you're a human and use Vim if you're 3xtra l33t) and fill it in with the requirements for getting Python to run on an Ubuntu container. # Using the Ubuntu image (our OS) FROM ubuntu:latest # Update package manager (apt-get) # and install (with the yes flag `-y`) # Python and Pip RUN apt-get update && apt-get install -y \ python3.8 \ python3-pip
🌐
Medium
medium.com › @ddasdocs › ubuntu-docker-container-python-openjdk-pyspark-ff8dc7cb4888
Ubuntu Docker Container — Python, OpenJDK & PySpark | by dwdas | Medium
August 19, 2024 - This Dockerfile creates a Docker image with Ubuntu 20.04, mainly for Python and Spark development with Java support.
🌐
CodeRivers
coderivers.org › blog › python-dockerfile-ubuntu-image-or-python-image
Python Dockerfile: Working with Ubuntu Images and Python Images - CodeRivers
January 26, 2025 - They are optimized for running Python applications and are a convenient starting point for containerizing Python projects. Base Image Selection: Dockerfile FROM ubuntu:latest This line tells Docker to start with the latest Ubuntu image as the base for our new image.