Install Python on Docker Containers

In this blog, I will show you how to install the Python interpreter on Docker container and start coding in it.
Python is an interpreted, high-level, and general-purpose programming language. Python's design philosophy emphasizes code readability with its notable use of significant whitespace.

Pre-requisites:

Docker should be installed.

Step 1: Create a Docker Container

We will use the centos image for creating the docker container. The version that we will use is the centos:latest.

Use the following command to create the Docker container

$ docker run -it --name python centos:latest bash

Let's see what this command does.
The -it options are used to get the interactive terminal so that we can run the command in the docker container.
The --name option is used to give the name to the docker container.
Next, we will give the image name. In this case, the image is centos:latest.
At last, we will tell the command to run. In this case, the command is bash.

Docker runs only one command when it creates the container and then stops the container after running that command. As we want to get the terminal so that we can run commands to install and use the Python interpreter on the docker container. The bash is the command that will give us the bash shell and this command will run forever if we don't exit from the container.

Step 2: Install Python interpreter

I will use the following command to install the Python inside the Docker container.

$ yum install python3

t11.png

t12.png

Step 3: Run the Python interpreter

Now, we can start coding inside Python by using a Python interpreter. To use the Python interpreter, run the following command.

$ python3

t13.png

Now, you are all set to run the Python programs inside the docker containers.