我使用OpenShift oc new-app
命令构建了一个容器映像。我不想将映像推送到本地容器注册表,而是想将生成的映像推送到私有注册表。当我使用Jenkins for CI / CD时,我想自动生成图像并推送到私有注册表。
我能够实现生成部分。但是震惊的是通过Jenkinsfile将映像推送到私有注册表。任何有关如何实现这一目标的指针都将受到赞赏。
答案 0 :(得分:0)
这篇Jenkins Building Docker Image and Sending to Registry文章讨论了如何做到这一点。
pipeline {
environment {
registry = "gustavoapolinario/docker-test"
registryCredential = 'dockerhub'
dockerImage = ''
}
agent any
tools {nodejs "node" }
stages {
stage('Cloning Git') {
steps {
git 'https://github.com/gustavoapolinario/node-todo-frontend'
}
}
stage('Build') {
steps {
sh 'npm install'
}
}
stage('Test') {
steps {
sh 'npm test'
}
}
stage('Building image') {
steps{
script {
dockerImage = docker.build registry + ":$BUILD_NUMBER"
}
}
}
stage('Deploy Image') {
steps{
script {
docker.withRegistry( '', registryCredential ) {
dockerImage.push()
}
}
}
}
stage('Remove Unused docker image') {
steps{
sh "docker rmi $registry:$BUILD_NUMBER"
}
}
}
}