We will create a script that will print a "Hello World!" message. And a numpy array, which contains some random numbers.

Requirements file

The first step in this process is to create a requirements.txt file. This file will contain all the dependencies that our application needs to run. In this case, we will only need numpy.

numpy==1.19.5

Python Script

Now, create a python script called main.py with the following content:

#!/usr/bin/python3

import numpy as np

print("Hello World!")
print(f"This is a test with numpy: {np.array([1,2,3])}")

Dockerfile

Now define, a Dockerfile with the following content:

FROM python:3
ADD requirements.txt /
RUN pip install -r requirements.txt
ADD main.py /
CMD ["python", "main.py"]

Build the Image

Now, you have to create a docker image with the following command:

docker build -t anuraganalog/pytest:latest

Run the Image

Now, you can run the image with the following command:

docker run anuraganalog/pytest:latest