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.
- Create an index.html custom apache HTML file.
$ vi index.htmlApache2 web application is running with version-1.0
2. Create a Dockerfile that contains instructions for the Docker
# Base Image
FROM httpd:2.4# MAINTAINER of the Dockerfile
MAINTAINER Bikram <email@example.com>#Copy the index.html file /usr/local/apache2/htdocs/
COPY index.html /usr/local/apache2/htdocs/#Expose Apache Port
3. After creating Dockerfile, Create a Docker Image.
$ docker build -t apache2-app .
4. Run Docker Image and Create a Container
$ docker run -d -p 8000:80 --name apache2-app apache2-app:latest
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.