Introduction:
Nov 29, 2016 For that, you need to first create a container with Ubuntu image and then install apache web server in it. The custom images can be uploaded to the repository. At Bobcares, we maintain a private docker registry for our internal Docker infrastructure, with custom images that are secure and optimized. This will be a very brief tutorial on Docker: we'll take a 'nginx' docker image and build a simple web server on Docker container. In that process, we can get a quick taste of how Docker is working. We'll learn: How to get an official image. How to use the files on host machine from our container. How to copy the files from our host to the. Apace Webserver:- Apache HTTP Server is a free and open-source web server that delivers web content through the internet. It is commonly referred to as Apache and after development, it quickly became the most popular HTTP client on the web. Search Docker Images: We would need to download Ubuntu image on host Ubuntu system on which we would install Apache web server. Varoius customize docker images are available on Docker repository which could be searched using the following command. This command would search and list all images having Ubuntu string in their name. Apache Web Server is the #1 web server in the world and powers most of the web servers on the internet. With Docker, we can deploy Apache without needing to configure it on our host machine.
In this post, we are going to see how to use docker httpd image and extend it to suit our needs and run the Apache web server as a Docker container.
We are also going to implement a docker reverse proxy as an additional example
Run Apache Web Server On Docker Linux - Learn IT And DevOps
Since we have targeted this post for Docker and Apache Installation and Configuration. We did not cover the fundamentals and basic components about Reverse Proxy but you can read, what is reverse proxy and how it is being configured in Traditional Apache Webserver in this link
I presume now you have understood what is Reverse Proxy and How it is working and configured in Traditonal and Normal Apache HTTPD Server environment.
Now let us move forward to the Docker Apache Image Creation and Reverse Proxy setup.
Steps Index:
- Choose the HTTPD Image from DockerHub (or) Optionally Download the image to Local
- Write Dockerfile and Use the Standard HTTPD image then Expand and Customize it.
- Create a Local httpd.conf file and Enable the modules you need
- Build and Create an Image using the Dockerfile
- Create Configuration and HTML files to feed the Container
- Create a WorkSpace
- Create two Directories named
sites
andhtmlfiles
to have conf and html files respectively - Create Virtual Host configuration file
*.conf
undersites
directory - Create Html files under
htmlfiles
directory
- Start the Container from your Apache HTTPD Docker Image with Necassary Volumes and Port forwarding.
- Access the URL and Validate the Reverse Proxy
Step1: Choose the HTTPD Image from DockerHub (Download the Image)
Let us choose the Official Apache HTTPD Latest image and also download it to local using
docker pull
CLI commandin your master server where you are running the
Docker Container Engine (CE)
use the docker pull command like thisIn fact, you do not have to explicitely mention the word
latest
here. If you just mention httpd
the latest image would be picked up.Note*: You can make sure the image is downloaded or not using the
docker images
CLI commandStep2: Dockerfile to Create a Customized HTTPD Image
Now there might be a question, Why can’t we use the httpd image as it is ?
The Answer is, The downloaded standard
httpd
image would have very minimal number of modules enabled. In order to implement reverse proxy we need to enable few modules like mod_proxy, mod_slotmem_shm, mod_watchdog etc.Also, we need to enable the Support for our customized Virtual Host file and HTML files in the Container before we create it, Later during the startup time we can supply these (conf,html) files to the container
Here is the Docker file with self-descriptive comments for each line.
Step2a: Take the Standard httpd.conf file for apache2 and enable the modules you need
I have downloaded the standard
httpd.conf
file and enabled the necassary modules like mod_proxy
, mod_ssl
etc.![Apache web server dockerfile Apache web server dockerfile](/uploads/1/1/8/6/118696348/328175605.png)
Copy the Content from the aforementioned link and create a file named
httpd.conf
in the same Directory where the Dockerfile
is located.If you look at our customized
httpd.conf
we have also added a Directive named IncludeOptional
to add a directory of configuration where our Virtual Host conf files can be placed.Any
*.conf
files placed in this directory would be considered by Apache HTTPDIf you scroll back and look at our Dockerfile once again you can see that we are creating this directory
So this
sites
directory is our Dedicated configuration files location where we can place our Virtual Host conf filesStep3: Build and Create an Image from the Dockerfile
![Apache Web Server Docker Apache Web Server Docker](/uploads/1/1/8/6/118696348/324378061.png)
In the Same Directory where our Dockerfile and httpd.conf file is present. Execute the following command
Now the Image is ready and available in your Local Images Repository and the image name is
httpd-proxyenabled
Step4: Create the Configuration files and Directories( Virtual Host and Html files)
Now we are going to create our Virtual Host (A WebSite) configuration file and it will be loaded into the container when it is being started.
It is not recommended to Share a Single file between Container and the Local Server. You always can share a Directory as a volume between a Container and a Host.
So we are going to create two new directories to keep our HTML and Conf files respectively and we are going to mount these directories as a Volume inside the container.
We will see how to do that in a minute.
Step 4a: Create a WorkSpace
Now choose some directory in your local system ( Mac/Windows) where Docker Container Engine is running and Let us call it as a workspace in my case it is /apps/docker/apacheconf
Step 4b: Create two Directories to place html and conf files
Create two Directories under the workspace to keep the virtualhost conf and html files.
Step 4c: Create Virtual Host configuration file under sites directory
Now go inside the sites directory and Create a Virtualhost configuration file ( A WebSite). If you have a Virtualhost file of your choice please use that or if you are following along, Please copy the following content and Save it as
techolaf.conf
Step 4d: Create the html file under htmlfiles directory
Save the following content into a file named index.html under the htmlfiles directory
Step5: Start the docker httpd Container with Volumes and Port Forwarding
Volumes – is a Docker terminology, It helps you Mount the local file system [directory] inside the container as a volume
PortForwarding – Forward the Container Port to host
Here
--publish
: to forward the container port 80 to Mac/Windows host’s port 90-d
: to run the container in background, Detached mode--name
: Name the container as apache server-v
: The Volume Mapping. Mounting the Host’s /apps/docker/apacheconf/sites
as /usr/local/apache2/conf/sites
inside the containerNow you can understand, that the directories we have created in local workspace are mounted inside the container and being used
In fact the Html and the configuration files we have placed in
sites
and htmlfiles
directory on the local are now being used by the container and our website techolaf.com
is readyNote*: Before validating the Site. You need to be aware the ServerName specified in the configuration file is techolaf.com and Apache would look for this name on the Address bar when you try to reach the website.
In enterprise these things are managed with internal DNS servers. For testing you can use your /etc/hosts file
Make an entry in your /etc/hosts file like shown below
127.0.0.1 www.techolaf.com
Now you are all set!.
Step6: Validate the Reverse Proxy
I hope you have your DNS records corrected.
With that assumption, let us go and hit the url
Steps To Build Apache Web Server Docker Image | By Vikash ...
http://www.techolaf.com:90/
and http://www.techolaf.com:90/mwi
The Configured and Desired result is when you try with no URI (or) the Home URL you should get the welcome html page you have created and when you are using the URI
mwi
it should load the content of our www.middlewareinventory.com
website home page.The Home Page [ Welcome html ]
The Reverse proxy Page with URI
Mission Accomplished!
I know there are lot of steps in here. But if you follow along you can get it done very easily.
Try it and let me know if you get any issues and feel free to comment for any help or support
Rate this article [ratings]
Cheers,
Sarav AK
Sarav AK
Follow us on Facebook or Twitter
For more practical videos and tutorials. Subscribe to our channel
Find me on Linkedin My Profile
For any Consultation or to hire us [email protected]
If you like this article. Show your Support! Buy me a Coffee.
For more practical videos and tutorials. Subscribe to our channel
Find me on Linkedin My Profile
For any Consultation or to hire us [email protected]
If you like this article. Show your Support! Buy me a Coffee.
Signup for Exclusive 'Subscriber-only' Content
More from Middleware Inventory
Apache Docker Config
- Apache Reverse Proxy - What is it and How to Configure Reverse ProxyIntroduction Proxy, In general terms it means 'a person who is authorized to act for another'. In Server infrastructure, a Proxy Server do the same thing, It stands in for some other server, which should be kept away and hidden for so many reasons. Proxy servers are used for both legal…
- Docker Run Image as Container - Create Container From Docker ImageIn this post, we are going to see how to create an image and run the image as a container and manage it. Before we proceed further, it is indispensable, that we are aware of what is an Image and What is a Container. So let us begin from there.…
- Apache Webserver Basic Authentication using htpasswd - How toOverview To Secure the Apache Virtualhost (or) a particular document root /directory. We can use this Basic Auth mechanism. When the user is trying to access the resource from the directory. User will be prompted for Authentication. Step1 Create a Password file with username and password entry using htpasswd tool. Available…
- Docker Weblogic : Run Oracle Weblogic 12c on DockerThe Introduction to Docker Weblogic In this post, we are going to be exploring the quick and easy option available to get started with weblogic and Docker. In this post, we are going to see how to create a weblogic container in docker in a few easy steps. The post's…
- Docker Tomcat Example - Dockerfile for Tomcat, Docker Tomcat ImageIn this post, we are going to learn how to install a Tomcat Application Server or Web Container on Docker and Deploy web applications into the Tomcat running inside Docker. This post is all about Docker Tomcat and deploying war web application into tomcat docker, Sample Docker Tomcat image, Dockerfile…