docker与jenkins学习
Posted stanljj
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了docker与jenkins学习相关的知识,希望对你有一定的参考价值。
docker命令:
docker create <image-id>
docker start <container-id>
docker run <image-id> = docker create <image-id> + docker start <container-id>
docker ps
docker ps -a
docker images
docker images –a
docker stop <container-id>
docker kill <container-id>
docker pause <container-id>
docker rm <container-id>
docker rmi <image-id>
docker commit <container-id>
docker build
docker exec <running-container-id>
docker inspect <container-id> or <image-id>
docker save <image-id>
docker export <container-id>
docker history <image-id>
Dockerfile
FROM jdk8:slim
ADD target/udap-user.jar app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom" ,"-jar" , "-Xms128m","-Xmx128m" ,"/app.jar"]
Jenkinsfile
pipeline {
agent { label ‘iclass5‘ }
stages {
//slave 机器执行编译打包上传
stage(‘Checkout‘) {
steps {
echo ‘start to check from github‘
checkout([$class: ‘GitSCM‘,
branches: [[name: ‘*/master‘]],
doGenerateSubmoduleConfigurations: false,
extensions: [
[$class: ‘SparseCheckoutPaths‘,
sparseCheckoutPaths:[[$class:‘SparseCheckoutPath‘, path:‘udap-user‘]]]
], submoduleCfg: [],
userRemoteConfigs: [[credentialsId: ‘github-wwlleo0730‘, url: ‘https://github.com/udap/mediabox‘]]])
}
}
stage(‘mvn build & test‘){
steps {
echo ‘start to mvn build‘
sh "docker run -i --rm -v ${env.WORKSPACE}/udap-user:/usr/src/workspace -v /root/.m2/repository/:/root/.m2/repository -v /opt/maven/settings.xml:/root/.m2/settings.xml -w /usr/src/workspace maven mvn clean package -U -Dmaven.test.skip=true"
}
}
stage(‘remove old container‘){
steps{
sh ‘‘‘CID=$(docker ps | grep iclass.cn/$JOB_NAME | awk ‘{print $1}‘)
if [ "$CID" != "" ];then
docker rm -f $CID
fi‘‘‘
}
}
stage(‘rebuild image‘){
steps {
sh ‘‘‘CID=$(docker images | grep iclass.cn/$JOB_NAME | awk ‘{print $1}‘)
if [ "$CID" != "" ];then
docker rmi iclass.cn/$JOB_NAME
fi‘‘‘
script {
docker.build(‘iclass.cn/$JOB_NAME‘,‘./udap-user‘)
}
}
}
stage(‘restart container‘){
steps{
echo ‘start..‘
sh ‘docker run -d --name $JOB_NAME -p 4010:4010 -e "SPRING_PROFILES_ACTIVE=test" -e "EUREKA_INSTANCE_IP-ADDRESS=10.80.228.221" iclass.cn/$JOB_NAME‘
}
}
}
}
以上是关于docker与jenkins学习的主要内容,如果未能解决你的问题,请参考以下文章