Pre-Requirments
- Jenkins with Maven Server
- Docker host
- Install Publish over ssh Plugin
- Enable connection between Docker and Jenkins
- Create user on Docker Host
Install "publish Over SSH" plugin
Jenkins Dashboard >> Manage Jenkins
> Manage Plugins
> Available
> Publish over SSH
and install
Enable connection between Docker and Jenkins
Jenkins Dashboard >> Manage Jenkins
> Configure System
> Publish Over SSH
> SSH Servers
- SSH Servers:
- Name :
docker_host
- Hostname:
<ServerIP>
- username:
dockeradmin
- password:
*******
- Name :
Test the connection by clicking Test Connection
and save
create a new user for Docker management and add user to Docker (default) group
useradd dockeradmin
passwd dockeradmin
usermod -aG docker dockeradmin
Creat docker
directory under /opt
mkdir /opt/docker
Write a Dockerfile
under /opt/docker
vi Dockerfile
# Pull base image
From tomcat:8-jre8
# Maintainer
MAINTAINER "maheshkumar.root@gmail.com"
# copy war file on to container
COPY ./webapp.war /usr/local/tomcat/webapps
Create Jenkins job
Jenkins Dashboard >> click New item
-
Enter item name:
Simple-Devops-Project-3
-
Source Code Management
- Repository :
https://github.com/ValaxyTech/hello-world.git
- Branches to build :
*/master
- Repository :
-
Build
- Root POM:
pom.xml
- Goals and options :
clean install package
- Root POM:
-
Send files or execute commands over SSH
- Name:
docker_host
- Source files :
webapp/target/*.war
- Remove prefix :
webapp/target
- Remote directory :
//opt//docker
- Name:
-
Exec command[s] :
docker stop mkn400_demo; docker rm -f mkn400_demo; docker image rm -f mkn400_demo; cd /opt/docker; docker build -t valaxy_demo .
- send files or execute commands over SSH
- Name:
docker_host
- Exec command :
docker run -d --name mkn400_demo -p 8090:8080 mkn400_demo
- Name:
-
Login to Docker host and check images and containers before run the job. (no images and containers)
Run Jenkins job
check images and containers again on Docker host. This time an image and container get creates through Jenkins job
Access web application from browser which is running on container
http://<docker_host_Public_IP>:8090