Configuring Apache Webserver in Docker Containers Using Jenkins
Let's create an automation repo today that will help you to install docker and the Configuring Apache Webserver.
What Is A Jenkins Job?
In simple words, any automated process that is implemented in Jenkins is a Jenkins Job.
The automated process can be about building the source code. The source code can be merged from any of the source code management like git, SVN, and perforce.
Create Job
Type a project name and select Freestyle project
Configure the job
Click on the configure option then you will be able to see the options to add the git repo and some more SCM options.
This will add the GitHub repo. All the codes will be downloaded to the respective location.
Github Repo Include Bash script:
sudo cat <<EOF > /etc/yum.repos.d/docker.repo
[docker]
name=docker
baseurl=https://download.docker.com/linux/centos/7/x86_64/stable/
gpgcheck=0
EOF
sudo yum install docker-ce --nobest -ysudo systemctl restart dockersudo docker pssudo docker run -dit --name myos1 -p 8085:80 centos:7
sudo docker exec -i myos1 yum install httpd -y
sudo docker exec -i myos1 yum install net-tools -y
sudo docker cp /root/a.html myos1:/var/www/html/
sudo docker exec -i myos1 /usr/sbin/httpd
Docker Script does the following:
- docker repo
- Install Docker
- Launch Container
- Copy HTML files in /var/www/html
- Restart httpd services
Execute Shell:
We need to Copy the docker.sh script inside the respective system.
Job Running Automatically:
- Poll SCM: Configure Jenkins to poll the SCM for ant pushes or commits and then trigger the jobs. Here we have given * * * * which means the Jenkins polls the SCM every minute.
Run the job:
After the build, you will see the output in Red/Blue colour.
The success represented by Blue Color 🔵
and Fail represented by Red Color 🔴
.
Console Output:
Check the Downloaded Files in your location.
Let's see our webpage with your public IP and port no.