install python in dockerfile

FROM python:3

ADD my_script.py /

RUN pip install pystrich

CMD [ "python", "./my_script.py" ]

Here is what the above code is Doing:
1. We’re using the python:3 image as our base image.
2. We’re adding our Python script to the container.
3. We’re installing the pystrich library.
4. We’re telling Docker to run our Python script when the container starts up.

Save the above code to a file named Dockerfile and build the image:

$ docker build -t my-python-app .

This will create an image named my-python-app. We can now run the image to create a container:

$ docker run my-python-app

This will output the following:

$ docker run my-python-app
Hello, world!

$

If we want to make our container interactive so that we can see the output of our script, we can use the -it flags:

$ docker run -it my-python-app

This will output the following:

$ docker run -it my-python-app
Hello, world!

$

We can also mount a volume so that we can edit our Python script and have the changes reflected in the container:

$ docker run -it -v “$PWD”:/app my-python-app

This will output the following:

$ docker run -it -v “$PWD”:/app my-python-app
Hello, world!

$

Now, every time we make a change to our Python script, we can just re-run the container and the changes will be reflected.