Automatic code Deploy in docker with Jenkins

Description:

Job Creation :

Step To create Job :

  1. Create Job
  2. Select freestyle
  3. Click ok

=> I created Job1 .

Now Configure Git Jenkins :

Job run periodically :

Execution of Shell :

Docker.sh (Shell Script) For docker detect and run and Jenkins job is use for run job periodically .

rpm -q docker-ce
x=$(echo $?)
if [[ $x == 0 ]]
then
sudo systemctl start docker
sudo docker run -dit — name os2 -p 8085:80 centos:7
sudo docker exec -i os2 yum install httpd -y
sudo docker exec -i os2 yum install net-tools -y
sudo docker cp /root/githubcode/ os2:/var/www/html
sudo docker exec -i os2 /usr/sbin/httpd
else
echo “[docker]
name=docker
baseurl=https://download.docker.com/linux/centos/7/x86_64/stable/
gpgcheck=0
“ > /etc/yum.repos.d/docker.repo
fi

Docker Script do the following:

  1. docker repo
  2. Install Dokcer
  3. Launch Container
  4. Copy html files in /var/www/html
  5. Restart httpd services

Now Click on Build Now : (So our Job Run )

Output :

Go to into Docker and See the Code which pull from the github by jenkins .

Now see Our Website is live :

Note : If you face any issue about denied then change /etc/sudoers file

and write Below Line

jenkins ALL=ALL NOPASSWD:ALL

Thank you ….

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store