【发布时间】:2022-01-27 04:02:52
【问题描述】:
在 Jenkins 流水线场景中,如何删除构建后剩余的镜像?
我现在登录虚拟机并使用手动命令:
docker images -q |xargs docker rmi
这是我的 Jenkins 脚本:
stage 'Deploy'
dir('/apps/npt'){
sh 'chmod +x deploy_prod.sh'
sh './deploy_prod.sh'
}
这是部署脚本:
#!/bin/bash
#build docker container
docker build -t nptproduction .
# stop existing container and remove image
docker stop nptproduction && docker rm nptproduction
# run new image
docker run -d -p 5021:4000 --name nptproduction nptproduction
我知道在部署脚本中我需要捕获任何错误,如果是这样,请不要停止/不要删除现有的(工作图像/容器),但这取决于未来的更新...
【问题讨论】:
标签: bash docker jenkins ubuntu-16.04