Setting up python interpreter and running py code on Docker

Karthik Avula
3 min readNov 2, 2020

Hey everyone, in this blog we will see how to setup python interpreter in our docker container and how to run our python code on the top of docker container.

First run docker ps command to see all the images that are running. In my case I don’t have any containers running.

docker ps
docker ps

If you dont have any Images in your system, you can donwload them using docker pull.

docker pull <image>:<version>

Now, run a new image in which you wish to run your python code and give it a name. For this you need to type docker run -i -t — name <Your Desired Name for Image> <image>:<version>

Here -i is for interaction and -t is to get a new terminal for our new OS(Image)

docker run -i -t --name DockerPy centos:7
Our new OS launched.

You know that if you want to run your python code, you need to have python/python3 interpreter. For this you need to install python3 using yum/dnf command. And proceed with a yes(y) option.

yum install python3

Now, python3 has been installed. Lets make python code to run on our docker container which contains python3 interpreter.

writing some py code in dockertest.py file

Now, we will run our python code using python3

python3 dockertest.py
Python code run successfully.

You will see the output of our python code, which means that our python interpreter has been installed successfully and now can be able to run python code our docker containers.

If you want to push this container to docker hub, you can use “docker push” along with name and some tags.

Thanks for reading my blog.

--

--

Karthik Avula

CS Student. Skillset : Linux, Bash Shell Scripting, Python, AWS, Hadoop, Ansible, Docker, Kuberntes, Networking and Troubleshooting, OS Concepts.