Run Simple Project with Apache in Docker
Today we’re going to learn how to build and run a project with Apache web server in Docker. Let’s start:You can take a look at basic docker commands.
Table of Contents
Create a Project
First of all, let’s create a simple project. I’m going to make a simple project. The project will contain only the index.html file. Your project may contain more files.
My docker project’s structure:
So, the main project’s files will be stored in the app folder.
Outside of the app folder, we need to create a file called Dockerfile. A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. To know more about Dockerfile, please Dockerfile reference.
We’re going to write all commands in Dockerfile to create a Docker image for our project.
# pull latest CentoOS FROM centos:latest # the maintainer name MAINTAINER Obydul # install apache RUN dnf -y install httpd # copy our app's files to apache's public dorectory COPY ./app/ /var/www/html/ # keep apache server running CMD ["/usr/sbin/httpd", "-D", "FOREGROUND"] # listen the port 80 for apache on CentOS EXPOSE 80
Build and Run as Container
We’ve created our project and wrote a Dockerfile to create an image. Let’s build the project:
docker build -t apacheserver ./
./ defines the Dockerfile’s location.
Now let’s run the container at our machine’s port 90:
docker run -p 90:80 apacheserver
http://localhost:90 and see the output. If you are testing on live server, you need to replace localhost with the server IP or hostname.
Preview may take a few seconds to load.
Below you will find some common used markdown syntax. For a deeper dive in Markdown check out this Cheat Sheet
Bold & Italic
Bold **double asterisks**
Three back ticks and then enter your code blocks here.
# This is a Heading 1
## This is a Heading 2
### This is a Heading 3
> type a greater than sign and start typing your quote.
You can add links by adding text inside of  and the link inside of (), like so:
To add a numbered list you can simply start with a number and a ., like so:
1. The first item in my list
For an unordered list, you can add a dash -, like so:
- The start of my list
You can add images by selecting the image icon, which will upload and add an image to the editor, or you can manually add the image by adding an exclamation !, followed by the alt text inside of , and the image URL inside of (), like so:
To add a divider you can add three dashes or three asterisks:
--- or ***