Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to automatically deploy scripts for Linux multi-application docker

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Linux multi-application docker how to automatically deploy scripts, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.

Linux multi-application docker automatic deployment scripts can be combined with jenkins distributed deployment

Parameters:

Image name: format of port: version number

For example: spring-client:8764:0.0.1

1. First use maven install to package the project to the target directory

two。 The Dockerfile path for the project is: / src/main/docker/Dockerfile

3. Scripts automatically copy Dockerfile and program files automatically package image deployment

Join the 4.docker command when it is run-- restart unless-stopped can be self-started with docker

Project= ("spring-client:8764:0.0.1"spring-system:8770:0.0.1"spring-eureka:8761:0.0.1") mainDir=/opt/jenkinsjenkinsDir=/root/.jenkins/workspace/spring-boot-xinjiang# determines whether the home folder exists, and there is no creation if [!-d $mainDir] Then mkdir $mainDirfi# circular array creates a folder for each project for var in ${project [@]} do OLD_IFS= "$IFS" IFS= ":" array= ($var) IFS= "$OLD_IFS" name=$ {array [0]} port=$ {array [1]} version=$ {array [2]} echo project name $name; if [!-d $mainDir/$name]; then echo "project directory does not exist, create project directory" mkdir $mainDir "/" $name fi cd $jenkinsDir " JarName=$name/target/$name-1.0.0.jar if [- f $jarName]; then echo "jar source file exists, copying" # copy program file (war/jar) name cp $jarName $mainDir/$name/$name-$version-SNAPSHOT.jar else echo "jar source file does not exist" fi # Dockerfile file path dockerFileName=$name/src/main/docker/Dockerfile if [- f $dockerFileName] Then echo "docker file exists, copying" # copying the name of Dockerfile program file cp $dockerFileName $mainDir/$name else echo "docker file does not exist" fi if [- f $dockerFileName] & & [- f $jarName]; then cd $mainDir/$name if docker ps-a | grep-I $name;then docker stop $name docker rm $name fi imagesid= `docker images | grep-I $name | awk'{print $3} '`if ["$imagesid" = ""] Then echo image does not exist else echo image exists build after deletion "if docker ps-a | grep-I $name;then echo" image container exists, stopping container "docker stop $name echo" image container deleting "docker rm $name fi docker rmi $imagesid-f fi docker build-t $name. Echo "Image Construction succeeded" echo Container Construction "docker run-d-p $port:$port-- name $name-- restart unless-stopped $dockerName $name echo" Container Startup succeeded "else echo" Image Construction failed "fidoneexit 0 is helpful to you after reading the above contents? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report