DockerFile Apache

Dockerize your Apache with Custom index.html

What is Dockerfile?

  • Dockerfiles enable you to create your own images.
  • A Dockerfile describes the software that makes up an image.
  • Dockerfile is a simple text file that consists of instructions to build Docker images.
  • Each instruction present in the docker file represents a layer of the docker image.

Here, we are creating an Apache application and using a custom dockerfile and index.html

Github link for Dockerfile- https://github.com/bikramatmedium/docker/tree/main/Dockerfile/apache

This example includes the following steps.

  1. Create an index.html custom apache HTML file.
Apache2 web application is running with version-1.0

2. Create a Dockerfile that contains instructions for the Docker

# MAINTAINER of the Dockerfile
MAINTAINER Bikram <bikramatmedium@gmail.com>
#Copy the index.html file /usr/local/apache2/htdocs/
COPY index.html /usr/local/apache2/htdocs/
#Expose Apache Port
EXPOSE 80

3. After creating Dockerfile, Create a Docker Image.

4. Run Docker Image and Create a Container

An explanation of this command is as below,

  • docker run command is used for creating a docker container.
  • -d option is used to run a container in the background and print container ID.
  • -p option is used for port mapping between container and Host machine.
  • — name option is used to assign a name to the container.
  • In the end, we provide the name of the docker image from which we wish to run our container.

This will start serving the static site on port 80. If you visit http://ip:8000 in your browser.