Setup an Apache Web Server in a Docker Container
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
Step 2: Now install docker Using the following command
yum install docker-ce — nobest
To start docker service use the command
systemctl start docker
Step 3: Now pull one image to run your containers on top of this
docker pull “image name ex. centos”
Step 4: Now launch a container using this image
docker run -it — name “any name to container” “image name ex. centos”
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
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.
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