Saturday, July 25, 2020

How to Build Apache Web Server Docker Image

Description: Here I have explained, how to build custom Apache Web Server Docker Image and create docker container using image.

Procedure:
  • First we create docker file to build Apache Web Server in Ubuntu. Docker file is like text file without having any extension
# mkdir /DockerDir [create directory to save file]

  • create index.html file under /DockerDir directory 
# vi /DockerDir/index.html


<!DOCTYPE HTML>
<html>
<body>

<h1> Server Techno Lab</h1>
<h2> https://servertecholab.blogspot.com/</h2>
</body>
</html>
</div>

  • Create Docker file for Webserver and copy index.html to docker image and run that URL on port 80
# vi /DockerDir/dockerfile

FROM centos:latest
MAINTAINER NewstarCorporation
RUN yum -y install httpd
COPY index.html /var/www/html/
CMD [“/usr/sbin/httpd”, “-D”, “FOREGROUND”]
EXPOSE 80
  1. FROM = container image name : tag
  2. MAINTAINER = Tag of Image
  3. RUN =  If you want to Run any command in container
  4. COPY = To copy files 
  5. CMD = Run command using bash 
  6. EXPOSE = Expose port number for service
  • Run Docker Build command to build docker file
# docker build -t="mywebserver" .


  • You can find your docker image using docker images command 
# docker images 


# docker run –d –p 80:80 mywebserver  

-d = Docker container deteched and runninin background
-p = Map Port number with container port apache will run on port 80

  • Finally you can browse server IP Address and default page of apache

No comments:

Post a Comment