7.2: Docker Task
In this article I will explain how to:
Create a Dockerfile file describing a simple Python container.
Task Description
🔅Configuring HTTPD Server on Docker Container
🔅Setting up Python Interpreter and running Python Code on Docker Container
Prerequisites
- Docker install in the base system.
- A runnable Python web page.
Step1: create Dockerfile
- In this Dockerfile we need to first select which docker image we need. here I am going create to create image using centos docker image.
- then I am installing 2 software 1. httpd server to configure the apache web server 2. python3.
- I am copying index.py file in /var/www/cgi-bin/ folder . content of index.py is below. this is simple python code to run date and cal command .
- then we can start service of web server. and expose this image to port no 80.
step2: create a image using this Dockerfile
command to create docker image using dockerfile
- docker build -t <any name > <path of Dockerfile>
we can see created docker image using command
- docker images
Step3: Luanch an Container using created image
command to launch conatiner using docker image
- docker run -dit -p 81:80 --name <container name> <image name>
- in the above command "-p" is used to expose the container so that we can access the web page outside the bash os too.
command to see the status of container
- docker ps and docker ps -a
step4: access the web page
we can access the web page which we have configure using apache web server and python3 code in /var/www/cgi-bin/ folder.
- http://192.168.43.182:81/cgi-bin/index.py
this is output of webpage, which is written in python language and running in docker container .
Software Engineer at SBS
4yVery useful
Software Engineer
4ynyc sulekha
Senior Data Engineer at Cigna | DevOps Advocate | IaC Expert | ETL | Data Lake | Terraform & AWS Certified Solutions Architect
4ynice work !!
DevOps Engineer at Celebal Technologies
4yThanks for sharing
Software Developer @Hotfoot ...😇
4yGreat work👌 sulekha