Apache Web Server Docker

  



If you are a Linux system administrator who provides support for developers, chances are you’ve heard of Docker. If not, this software solution will make your life easier beginning today by helping you reduce operating costs and accelerate deployments – among other benefits.

  1. Jun 21, 2018 Check Apache Page. If you wish, you can now stop the container. $ sudo docker stop tecmint-web and remove it: $ sudo docker rm tecmint-web To finish cleaning up, you may want to delete the image that was used in the container (omit this step if you’re planning on creating other Apache 2.4 containers soon).
  2. 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.

But it’s not magic. Docker as a platform leverages containers – packages of an application along with all the tools it needs to run to eliminate differences between environments.

Tutorial Apache - Testing the Docker installation Open your browser and enter the IP address of your web server. In our example, the following URL was entered in the Browser.

In other words, containerized software will operate and can be managed consistently regardless of where it is installed. Additionally, containers are much easier to set up, start, stop, and maintain than good old virtual machines. If you’re interested in knowing more about the differences between these two technologies, the official Docker website provides a great explanation.

To illustrate, in this article we will explain how to install Docker on CentOS 7 and Ubuntu 16.04, and spin up an Apache 2.4 container from Docker Hub.

We will then use it to serve a simple web page from our home directory – all without the need to install a web server on our host.

Installing Docker on CentOS and Ubuntu

To begin, let’s install Docker using the following command. This will download and run a shell script that will add the Docker repository to our system and install the package.

Next, use systemctl command to start the main Docker service and check its status.

At this point we can simply execute.

to view the list of available commands or to get help.

will tell us how to list containers present on our system, whereas

will print all the options that we can use to manipulate a container.

Setting Up an Apache Container

One of the amazing things about the Docker ecosystem is that there are tens of standard containers that you can easily download and use. In the following example we will instantiate an Apache 2.4 container named tecmint-web, detached from the current terminal. We will use an image called httpd:2.4 from Docker Hub.

Our plan is to have requests made to our public IP address on port 8080 be redirected to port 80 on the container. Also, instead of serving content from the container itself, we will serve a simple web page from /home/user/website.

We do this by mapping /home/user/website/ on the /usr/local/apache2/htdocs/ on the container. Note that you will need to use sudo or log in as root to proceed, and do not omit the forward slashes at the end of each directory.

At this point our Apache container should be up and running.

Now let’s create a simple web page named docker.html inside /home/user/website directory.

Add the following sample HTML content to file.

Next, point your browser to AAA.BBB.CCC.DDD:8080/docker.html (where AAA.BBB.CCC.DDD is your host’s public IP address). You should be presented with the page we created previously.

Check Apache Page

If you wish, you can now stop the container.

and remove it:

To finish cleaning up, you may want to delete the image that was used in the container (omit this step if you’re planning on creating other Apache 2.4 containers soon).

Note that in all the above steps we never had to install the web server on our host.

Summary

In this article we explained how to install Docker and manipulate a container. Unfortunately, these are just the basics – there are entire courses, books, and certification exams that cover Dockers (and containers in general) more in depth.

If you want to learn more about Docker, we have already covered a 3-article series, that explains how to install Docker, run applications into containers and automatically build docker images with dockerfile.

Consider this as your starting point and let us know if you have any questions or comments – we look forward to hearing from you!

  • Related Questions & Answers
  • Selected Reading

How To Setup A Simple Apache Web Server In A Docker Container

DockerOperating SystemOpen Source

No doubt that Docker containers are now being widely used for various purposes in the development lifecycle right from building, distributing, testing to deployment of the products. It allows developers to work on different parts of the project, collaborate with other developers working on the same project, helps in version management of the project and in some cases, also allows to test the product by hosting on its own servers.

Docker

Apache On Docker

Let’s say you have built a static website inside the docker container and now you want to test that website by running it on a browser. Docker allows you to create an apache server inside the container and host the website locally and connect it via ports so that you can display it on your local machine.

In this article, we are going to see how we can run a static site on an apache server inside a docker container and access it on our local machine. To start with, we need to create a dockerfile so that it can build an environment which has an apache server installed in it. We also need a simple static website which we would run on that server. A static website is one which does not render data and information dynamically or on the go and mostly consists of html and css and without javascript.

Let’s create a dockerfile and include commands to pull a base image which would contain the apache server pre-installed. Httpd is the dominant http server which contains the web server application called Apache.

We use the FROM instruction to pull that base image. We then create a directory called mysite which contains an html file called index.html which would contain the html content of our static website. Hence, the directory structure would be the main folder inside which we would have our dockerfile and a folder called mysite and inside that folder would be our index.html file.

Index.html

Dockerfile

We set our working directory inside the container to be /usr/local/apache2/htdocs/ and then we copy the mysite folder which contains the html file to our working directory in the container.

After we have completed our index.html file and the dockerfile, we are set to build our docker image using the docker build command with the help of our dockerfile. To build the docker image, we use the following command −

The above command builds an image called static-image. Now that we have built our image, we can start a container by using the docker run command. In order for the docker container to serve our website on the browser in our local machine, we need to connect the ports of our docker container and the local system. We can do so by using the −p flag with our docker run command.

The above run command connects the port number 80 of our container and local machine with each other. Using the −−name option, we have provided a name to our container called static−image−1. After executing this command, we have the docker container static−image−1 running and ready to serve our static website on the address http://localhost:80

Apache Docker Image

You can now fire up your browser and browse the link http://localhost:80 . You will see the content “Welcome to TutorialsPoint Docker tutorials” being displayed there. This means that the site is being served on the apache server.

To conclude, you can use docker containers to serve your static website. When you make changes in the website html, you will see the changes being reflected in the website display as well. You can also specify a different port number if you have some other application being served on that container.