Setting up Python Interpreter and Running Python Code on Docker Container
In this guide,we will configure and start Docker services,launch a Docker container,set up python interpreter and run a python code inside the container
What is Docker?
Docker is a software platform for building applications based on containers — small and lightweight execution environments that make shared use of the operating system kernel but otherwise run in isolation from one another. While containers as a concept have been around for some time, Docker, an open source project launched in 2013, helped popularize the technology, and has helped drive the trend towards containerization and microservices
What is Docker Container?
Docker Container is a standardized unit which can be created on the fly to deploy a particular application or environment. It could be an Ubuntu container, CentOs container, etc. to full-fill the requirement from an operating system point of view. Also, it could be an application oriented container like CakePHP container or a Tomcat-Ubuntu container etc.
Now that we know what is Docker and Docker Container we can start with the practical.
Create Yum Repository for Docker
Docker is a package which needs to be installed.For every package to be installed in Redhat Linux OS we require an rpm file of that software.The Docker rpm file is not available directly on the redhat iso dvd.So,we have to create a separate yum repository for docker and provide the docker rpm download link as baseurl.
In the /etc/yum.repos.d/
directory,create a file with .repo extension and the following content
[docker]
baseurl=https://download.docker.com/linux/centos/7/x86_64/stable/
gpgcheck=0
Install docker software
Install docker using the following command
yum install docker-ce -y --nobest
Start docker services
Start docker services using the following command
systemctl start docker
Pull the centos image from Docker Hub
For launching any container we require it’s image.Docker hub is a public repository from which we can download the images.
Pull the centos image using the following command
docker pull centos
Launch Docker container
We can launch docker containers using the docker run
command
docker run -it --name pythonos centos:latest
After running this command,we will get an interactive terminal(bash shell) which belongs to the container launched.
Install Python inside the container
Inside the container we have to install the python software using the following command
yum install python36 -y
Create a python code and run it
After installing python,we can create a python code and run it
Thus,the python code is running successfully inside the docker container.
Thank You!