我有 2 个 ec2 实例 第一个:托管 jenkins 和 docker,它从 jar 文件构建图像,然后将其推送到 docker hub repo
第二个:这将是我的应用程序服务器,它将包含 docker,它将从 docker hub 提取此镜像并在 docker 引擎上运行容器
我已经完成了创建图像并将其推送到 docker hub 的第一部分
我的问题是如何从 jenkins 管道到我的应用程序服务器执行 docker 命令,以从 docker hub 提取镜像并运行它
最佳答案
我找到了解决问题的方法
我在jenkins上使用了SSH Steps插件插件
其在管道中的编写如下:
stage('run commands on remote server') {
steps {
script {
def remote = [:]
remote.user = 'ec2-user'
remote.host = 'public or private ip of the remote server'
remote.name = 'ec2-user'
remote.identityFile = 'path for your ec2 private key'
remote.allowAnyHosts = 'true'
sshCommand remote: remote, command: 'your command 1 here'
sshCommand remote: remote, command: 'your command 2 here'
}
}
}
关于docker - 如何使jenkins管道在远程服务器上运行docker命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62346792/