While we believe that this content benefits our community, we have not yet thoroughly reviewed it. If you have any suggestions for improvements, please let us know by clicking the “report an issue“ button at the bottom of the tutorial.
Hello, readers! In this article, we will be focusing on Building an Apache Web Server through a Dockerfile.
So, let us begin! :)
Apache Server is an open source web server to configure and host the web applications online and locally as well using localhost as the medium.
It requires a lot of configuration when one wishes to set up an apache server on the workstation.
To reduce this over, Docker has introduced the concept of Dockerfile to build and set up configurations easily.
In the course of this topic, we will be setting up Apache server on our systems with just minimal steps to work with.
Let us begin :)
We need to follow the below steps to set up an Apache Server through a Dockerfile-
At first, we make use of the below mkdir command to create a directory specifically for all the apache related files.
Having created a folder as shown above, now we go ahead and create a Dockerfile within that folder with the vi editor –
As soon as we execute the above command, a vi editor opens. Paste the below content in the Dockerfile and perform the below steps to exit the editor-
FROM ubuntu RUN apt update RUN apt install –y apache2 RUN apt install –y apache2-utils RUN apt clean EXPOSE 80 CMD [“apache2ctl”, “-D”, “FOREGROUND”]
Now, we build the Dockerfile using docker build command. Within which, we tag the image to be created as 1.0 and give a customized name to our image i.e. apache_image.
docker build -t apache_image:1.0 .
Once the image has been built, we should check for the presence of the image using docker images command.
The docker images command gives us a list of all the images that are built or pulled from any public/private registry.
docker images REPOSITORY TAG IMAGE ID CREATED SIZE apache_image 1.0 a738dbef66ef 15 seconds ago 133MB
Once the image has been built, run the image as a container locally. For the same, the below configurations are required–
Thus, docker run command also takes the image along with the associated tag as input to run it as a container.
docker run --name myapache -d -p 80:80 apache_image:1.0
docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 443848c30b74 apache_image:1.0 "/docker-entrypoint.…" 7 seconds ago Up 6 seconds 0.0.0.0:80->80/tcp myapache
In order to test the presence of Apache server on the system, visit any local browser and type localhost.
The below page should be seen as output–
By this, we have come to the end of this topic. Feel free to comment below, in case you come across any question.
For more such posts related to Docker, Stay tuned with us.
Do let us know your experience in setting up the Apache Server onto your workstations, in the comment box.
Till then, Happy Learning! :)
Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in our Questions & Answers section, find tutorials and tools that will help you grow as a developer and scale your project or business, and subscribe to topics of interest.Sign up
Click below to sign up and get $100 of credit to try our products over 60 days!