deploy images to server
Install ‘Publish Over SSH’ plugin
![CI/CD with Jenkins – Part 8: deploy docker images 1 image 20200423004532272](https://www.gosysops.com/wp-content/uploads/2020/05/image-20200423004532272-1024x233.png)
Copy ssh key to server 192.168.1.4
sh-copy-id 192.168.1.4
Configure publish Over SSH
![CI/CD with Jenkins – Part 8: deploy docker images 2 image 20200423010448812](https://www.gosysops.com/wp-content/uploads/2020/05/image-20200423010448812-1024x549.png)
Create jenkins_folder and upload shell script on production server
mkdir /opt/jenkins_shell
chmod +x /opt/jenkins_shell/deploy.sh
deploy.sh shell script
#! /bin/sh
harbor_url=$1
harbor_project_name=$2
project_name=$3
tag=$4
port=$5
imageName=$harbor_url/$harbor_project_name/$project_name:$tag
echo "$imageName"
#check docker container, if existing, delete it
containerId=`docker ps -a | grep -w ${project_name}:${tag} | awk '{print $1}'`
if [ "$containerId" != "" ] ; then
#stop container
docker stop $containerId
#delete container
docker rm $containerId
echo "delete container successfully"
fi
#check image, if existing, delete it
imageId=`docker images | grep -w $project_name | awk '{print $3}'`
if [ "$imageId" != "" ] ; then
#delete image
docker rmi -f $imageId
echo "delete image successfully"
fi
# login Harbor
docker login -u eric -p Eric123456 $harbor_url
# download image
docker pull $imageName
# start container
docker run -di -p $port:$port $imageName
echo "start container successfully"
Add string patameter ‘port environment’
![CI/CD with Jenkins – Part 8: deploy docker images 3 image 20200423012535642](https://www.gosysops.com/wp-content/uploads/2020/05/image-20200423012535642-1024x377.png)
check docker image on production server
![CI/CD with Jenkins – Part 8: deploy docker images 4 image 20200423012012402](https://www.gosysops.com/wp-content/uploads/2020/05/image-20200423012012402-1024x76.png)
build task
![CI/CD with Jenkins – Part 8: deploy docker images 5 image 20200423013928783](https://www.gosysops.com/wp-content/uploads/2020/05/image-20200423013928783-1024x480.png)
check deployment status
![CI/CD with Jenkins – Part 8: deploy docker images 6 image 20200423013952837](https://www.gosysops.com/wp-content/uploads/2020/05/image-20200423013952837-1024x110.png)
![CI/CD with Jenkins – Part 8: deploy docker images 7 image 20200423015439653](https://www.gosysops.com/wp-content/uploads/2020/05/image-20200423015439653-1024x466.png)