所以我试图在我的docker swarm中运行jenkins,我希望它能够执行docker命令来构建新的docker镜像。
当我使用docker-compose脚本在本地运行时:
let folderPathFromConfig = vscode.workspace.getConfiguration('pasteImage')['path'];
if (vscode.workspace.workspaceFolders !== undefined) { // is undefined if no folder is opened
let workspaceRoot = vscode.workspace.workspaceFolders[0];
folderPathFromConfig = folderPathFromConfig.replace('${workspaceRoot}', workspaceRoot.uri.path);
}
它完全按照我的意愿工作,它可以构建以下jenkinsfile:
version: '2'
services:
jenkins:
build: ./jenkins
image: munhunger/jenkins
container_name: "jenkins"
ports:
- "81:8080"
environment:
- minio_url=<URL>
- minio_access=<TOKEN>
- minio_secret=<SECRET>
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /root/.jenkins/workspace:/root/.jenkins/workspace
- /var/lib/jenkins:/var/lib/jenkins
- /var/lib/docker:/var/lib/docker
问题是似乎无法将其部署到我的docker swarm。
我一直在pipeline {
agent any
stages {
stage('build war') {
agent {
docker { image 'gradle:latest' }
}
steps {
sh 'gradle war -b oven/build.gradle'
}
}
stage('build dockerimage') {
steps {
script {
dir('oven') {
def image = docker.build("munhunger/highly-oven")
docker.withRegistry('https://registry.hub.docker.com', 'docker-hub-credentials') {
image.push("${env.BUILD_NUMBER}")
image.push("latest")
}
}
}
}
}
}
}
。这是使用Portainer进行部署时。我是否错误配置了某些内容或发生了什么?
编辑:
我测试了使用invalid mount config for type "bind": bind source path does not exist
docker stack deploy -c jenkins.yml jenkins
但我仍然得到version: '3'
services:
jenkins:
image: munhunger/jenkins
container_name: "jenkins"
ports:
- "81:8080"
environment:
- minio_url=<URL>
- minio_access=<ACCESS>
- minio_secret=<SECRET>
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /root/.jenkins/workspace:/root/.jenkins/workspace
- /var/lib/jenkins:/var/lib/jenkins
- /var/lib/docker:/var/lib/docker
答案 0 :(得分:3)
没有理由使用bind-mounts或docker socket在docker容器中使用Jenkins。可以使用命名卷来存储重要(持久)配置数据,但是您可以使用docker命令构建映像,而无需使用主机docker socket。
请参阅https://hub.docker.com/r/jenkins/jenkins/
和https://hub.docker.com/_/docker/(docker in docker)
答案 1 :(得分:2)
您需要使用docker compose version: '3'or greater
将服务部署到swarm。
$objectToArray
使用docker stack deploy
部署撰写文件 -
$size
撰写参考 - https://docs.docker.com/engine/swarm/stack-deploy/
仅供参考 - docker撰写v3并不支持build
,您需要将图像提供给群组才能进行部署。