docker+jenkins+gitlab+dockerfile部署配置

第一步:docker+jenkins+gitlab自動化部署配置,這裏不說了,請看個人另外一篇文章java

第二步:pom.xml和Dockerfile配置內容git

pom.xmlspring

<build>
        <finalName>${project.artifactId}-${project.version}</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>1.0.0</version>
                <!--docker鏡像相關的配置信息-->
                <configuration>
                    <!--鏡像名,這裏用工程名-->
                    <imageName>${project.artifactId}-${project.version}</imageName>
                    <!--Dockerfile文件所在目錄-->
                    <dockerDirectory>${project.basedir}/src/main/resources</dockerDirectory>
                    <!--TAG,這裏用工程版本號-->
                    <imageTags>
                        <imageTag>${project.version}</imageTag>
                    </imageTags>
                    <dockerHost>http://你的ip:2375</dockerHost>
                    <registryUrl>http://你的ip:5000</registryUrl>
                    <pushImage>false</pushImage>
                    <imageName>你的ip:5000/${project.artifactId}:${project.version}</imageName>
                    <!--構建鏡像的配置信息-->
                    <resources>
                        <resource>
                            <targetPath>/</targetPath>
                            <directory>${project.build.directory}</directory>
                            <include>${project.artifactId}-${project.version}.jar</include>
                        </resource>
                    </resources>
                </configuration>
            </plugin>
        </plugins>
    </build>

 

/src/main/resourcesDockerfile的內容docker

FROM java:8
ENV project bdkt-eureka
ENV version 1.0-RELEASE
ENV home_path /home
WORKDIR $home_path
ADD /$project-$version.jar $home_path/$project.jar
ENTRYPOINT ["java", "-jar", "bdkt-eureka.jar"]

FROM java:8   依賴於jdk
ENV project bdkt-eureka   環境變量 key value
ENV version 1.0-RELEASE
ENV home_path /home
WORKDIR $home_path  指定的工做目錄
ADD /$project-$version.jar $home_path/$project.jar  複製功能
ENTRYPOINT ["java", "-jar", "bdkt-eureka.jar"]  至關於 java -jar bdkt-eureka.jar,這個命令就是把幾個逗號裏面的內容用空格拼接出來執行bash

第三步:構建任務中須要的配置ssh

Pre Steps  1maven

bdkt-parent/bdkt-basics/bdkt-eureka/pom.xml
clean install

 

Pre Steps 2spring-boot

內容爲:gitlab

#!/bin/bash
#鏡像名稱
image_name=47.111.115.253:5000/bdkt-eureka
#啓動的鏡像運行的名字
run_image_name=bdkt-eureka
#版本
version=1.0-RELEASE
result=$(docker ps | grep "$run_image_name")
if [[ "$result" != "" ]]
then
echo "stop $run_image_name"
docker stop $run_image_name
fi
result1=$(docker ps -a | grep "$run_image_name")
if [[ "$result1" != "" ]]
then
echo "rm $run_image_name"
docker rm $run_image_name
fi
result2=$(docker images | grep "$image_name")

if [[ "$result2" != "" ]]
then
echo "rmi $image_name:$version"
docker rmi $image_name:$version
fi

Pre Steps 3ui

內容爲:

clean package -f bdkt-parent/bdkt-basics/bdkt-eureka/pom.xml -DskipTests docker:build

 

 

Pre Steps 3

內容爲:

其中ssh site是本身配置的,詳細看我以前文章

docker run --name bdkt-eureka -p 8100:8100  -idt 47.111.115.253:5000/bdkt-eureka:1.0-RELEASE
docker logs bdkt-eureka
相關文章
相關標籤/搜索