Configure HTTPD server and setup Python Interpreter on Docker Container
Docker is a software platform that allows you to build, test, and deploy applications quickly. Docker packages software into standardized units called containers that have everything the software needs to run including libraries, system tools, code, and runtime. Using Docker, you can quickly deploy and scale applications into any environment and know your code will run.
Let’s do the task…
1. Configuring HTTPD Server on Docker Container
Step-1 : For the first time, We need to install Docker software in our system.
- To install docker , first create a docker repository inside /etc/yum.repos.d/ folder. Write the following code in the docker repository.
- Use yum install docker-ce — nobest command to install docker.
- Check the version of docker : docker — version
- After installation , We need to check whether the docker service is running or not : systemctl status docker
- To start the docker service use : systemctl start docker
Now , Docker has been installed successfully.
Step-2 : Pull a CentOS image from Docker Hub to launch a container : docker pull centos:latest
Step-3 : Launch a container named “web-conf”using CentOS image : docker run -it — name web-conf centos:latest
Step-4 : Install the httpd webserver using command : yum install httpd
Step-5 : Create webpages in /var/www/html/ document root
Step-6 : Now , start the httpd service . As docker container doesn't support systemctl command , So use /usr/sbin/httpd .
- To get IP address of the container we need ifconfig command but it is not installed in the OS , So install net-tools software that provides ifconfig command : yum install net-tools
- Check the IP address using command : ifconfig
Step-7 : All configuration has been done. Now See the webpage in the browser by typing : http://172.17.0.2/webpage.html
2. Setting up Python Interpreter and Running Python Code on Docker Container
Step-1 : First We need to install python3 inside the Docker Container. command : yum install python3
Step-2 : To confirm python installation , check python version command :python — version
Step-3 : Now , Use Python3 REPL Interpreter to run your python code.
Task completed ✌️✌️