Setup an Apache Web Server in a Docker Container
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYa0VYurBrPqVPjvscxH-tMoZwxT3ylOB7LYsCM6fts3c04lzh2V1R97WSGk8CT3tFlEccM9GLYo595jaVjEWQ2sVdBOJbj4Gcaa6ITYb6BShiI__Rq7jxPO16Dv3GN3HJvcSqUr1XskI/s16000/1_OOUJ3NyR6CbK368ImSbo8A.png)
Task Objective:-
Configure HTTPD Server on Docker Container so we can use it as a webserver
What is Web-Server?
A web server is a computer where the web content is stored. Basically, a web server is used to host the websites but there exist other web servers also such as gaming, storage, FTP, email, etc.
The most famous web server is the APACHE web server apache webserver is also known as HTTPD server.
What is Docker Container?
Docker containers are a technology that allows you to package and isolate applications with their entire runtime environment with all of the files necessary to run. This makes it easy to move the contained application between environments (dev, test, production, etc.)
Let’s Get Started
To Perform this practical you need the Docker repo and we also have to configure it so we can install docker ultimately we can do our HTTPD demo.
Step 1: Configure the yum repository so we can install docker
This is the URL you need to use at the place of BaseURL
https://download.docker.com/linux/centos/7/x86_64/stable/
Create one File “docker.repo” extension should be “.repo” and in that file write the following lines
[docker] ##any name to repo please write as it showed
baseurl= https://download.docker.com/linux/centos/7/x86_64/stable/ ##link to get docker
gpgcheck=0 ##set to 0 so no GPG authentication issue and save the file
Run the following command to check docker repo working or not
yum repolist
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2WW2ON1_I2_Eiod3fyO2-7XKedBO7oaWvgonuAizXUnm5KOETLRYEIG5oH-aRf6qenPM9koXYyKoEV04SxhDkPesyFUs5KOksEX8cZ71QAc1rttjbYTaDpy7lPfSd2LePQspe3wEKevY/s16000/1_EWXWZHJaKdRyeGaj4T_mlw.png)
Step 2: Now install docker Using the following command
yum install docker-ce — nobest
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjbxXwSqVORNicjvftwc_LBrOF220Ng4Ubchc7n_VD31IwUDTEq22UQAgEMMn6ywftfa1k-6rE5zBry5GXxL2JWCL4Ub4XGHVVzQleGags0pDnvjs4OXutbL8eHiqdAQ2a4WXH9lVlskO0/s16000/1_Fv2PW8s0ndjNcMSQjWqMWw.png)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNo21pz3pcvumNG_qvL72XokHRoUc9_WyURRRwoKHGDS-P_lDhLji8WijsJvpXcruBg5CeoDwiCMapdn_HGmvQUmc0hhtEvD5h1Ya-nHR-s0Ws6hzP351gK8AS2OM8R7OaLgh2XHwqtRg/s16000/1_WqKPoWbZY1l4CnRN254HDQ+%25282%2529.png)
To start docker service use the command
systemctl start docker
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNKwFG1rFP7_aDJfpY2uXTWIa20RNYGHdm2uDXBU-WNNTbDnRApJ_cPT4_8dtCdjIvv59kQ4WMqxnrZsrqsUCRL5iV5wF5VSg8vQKCINNr-LnX3tM2VDCQJOhoGIqPM2O4BlHIeJk9Moo/s16000/1_-IFg2xVUfNPVx2LPlDQ-eA.png)
Step 3: Now pull one image to run your containers on top of this
docker pull “image name ex. centos”
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQAO-AS5qE2rXIlp_V3Qnal3V9SyrcumhSaoFn7dr3RDTOU_vsL0tE1h80hS19tAXdGcBd2zfwm1frxxWD8Y3RaAi5QbUVDffQQZ6lVFInVFPU5WQvSh-OojWoQVXvTZY81mfY4aDdsMU/s16000/1_rBii_-ua9e5WAr9T2Bjfqw.png)
Step 4: Now launch a container using this image
docker run -it — name “any name to container” “image name ex. centos”
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7VXjzD82-orYjwAIcKWCnpfJ31mH9Jg3M14SGXWI80ZdXRh8W5vaBrS-brcce3zYk2ucmqjqMp63G4axG5rTZMnoWe1NobwAPbXg8t33uTva417u9gsLTGsPbEci4B1OGp-tkbP0Hiq0/s16000/1_QBm29nUf3TEK_tWDN2pXkQ.png)
Step 5: you will get a docker prompt as you can see on the above image and the following are the steps performed inside the container for the HTTPD server
So we got our container Now we need to install the Apache webserver as we have mentioned in the title
Please run the following command in the container to install the HTTPD server:
yum install httpd
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJZzqLVFT2JsBQ2jQ2B85YjZjLeJo-b6B6Y8-lPj5KNNVG3Nonlw0HuCXlB-wisnxYN67eHLr2SF28YamyVVUkStaA-kk188z2Wm4vjy7ATjUfyH8S7HDB8xJAkwifVNzDy-KE-lglNwE/s16000/1_73FS4I_gh9ChjJay55ZdJQ.png)
Step 6: Now service will start automatically or you can use the following command(inside the container) to start manually
/usr/sbin/httpd
Step 7: In this step, we will see a common problem that is if we exit the container and start again, the site is down. So we need a fix that issue
the service should auto starts during boot.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHT14pYeMhDACYrUlXAdlH36bP2304dmuktJ44BRebyE2-6ysQBYYGMjb4WneMAoeWkFW8Z85Nn2fYFTrRUdLhqElaTLIKSblgoUu3riCTTIXiBs9PGIlPuPpUZo9kwzl2LG7QhcRR0fw/s16000/1_FiHWX2rv56z0LXcCfAEpgQ.png)
In the following file just update the path of your web server:
file: /root/.bashrc
path: /usr/sbin/httpd
so whenever you launch the same container HTTPD service automatically start so you don't need to start it again and again you can see the below image
Conclusion:-
With the Docker concept, we have launched the HTTPD server on the container and we have applied all the necessary concepts that need to apply ultimately we able to Launch a webserver on the Docker container.
No comments