How to use docker as a web server

Shubham Jangid
Oct 28, 2020

--

Hosting web page on the top of docker

Step 1: — Create a repo file to install docker community edition

vi /etc/yum.repos.d/docker.repo

Docker community edition not for RHEL8, so we hear give link for centos 7

step 2 : — install docker in our system

we use yum for install packages in RHEL8

Step 3 : —Download centos docker image

we use docker pull <image_name>:<tag> for download docker image

Step 4 : — Start services of docker

Step 5 : — Launch Docker container with centos docker image

hear we use -p for patting so we can also use the services of docker outside the RHEL8

  • -i for launch container in interactive mode
  • -t for provide terminal (tty)

— name argument use for give the name of docker OS

Step 6 : — Install apache httpd package in the docker image

Step 7 : — Start the service of web server

In docker we can’t use systemctl cmd for start services of any services because docker not boot it only used shared resources of docker host (RHEL8)

/usr/sbin/httpd is path were the httpd program available

Step 8 : — Create an index.html file in /var/www/html/ directory

/var/www/html is default document directory of apache web server

It’s Only for learning purpose you can add other web pages also as per your requirements

Final Output

<ip of RHEL8 OS>:<port number which is initialize at time of launching container>

Run Python Program in docker image

Step 1: — Install python3 package in docker os

hear we use version 3 of python so use python3

Step 2 : — Write a simple python program

use vi editor to run python program

Step 3 : — Run python program

python3 <program_name>

Thank you

--

--

No responses yet