Tuesday, July 14, 2020

How to Setup Apache Web Server in a Docker Contaier

Description: Here I have explain how to setup Simple Apache Web Server in Docker Container. 

Procedure:

  • First install Docker on Centos and Ubuntu. Below command will download and run script that will add the Docker Repository and install package.
# curl -fsSL https://get.docker.com | sh

  • After installation start and check status of Docker service using below command
# systemctl start docker
# systemctl status docker
  • Now you can run docker command given in this URL
Setting UP Container:  There are many container for same technology, So in this blog we are using Apache 2.4 and named it to ServerTechLab-Apache. Once we get image we setup apache on 8080 port on our IP address to port 80 on container. We will setup simple page on /home/ServerTechLab. 

To setup this we will map /home/ServerTechLab [On Local Server] to /usr/local/apache2/htdocs [On container Machine]

# docker run -dit --name ServerTechLab-Apache -p 8080:80 -v /home/ServerTechLab/:/usr/local/apache2/htdocs/ httpd:2.4

  • If you have Selinux running on Server then you will get 503 authorization error. To Over come this issue you need to use :Z
# docker run -dit --name ServerTechLab-Apache -p 8080:80 -v /home/ServerTechLab/:/usr/local/apache2/htdocs/:Z httpd:2.4
  • You will find docker container is running check by using below command.
# docker ps
  • Create test html page on /home/ServerTechLab and browse it by http://IP_Addr:8080/test.html
  • If you want to stop and remove container, you can do it by using below commands
# docker stop ServerTechLab-Apache
# docker rm ServerTechLab-Apache         

No comments:

Post a Comment