docker - 如何使jenkins管道在远程服务器上运行docker命令

标签 docker jenkins ssh jenkins-pipeline

我有 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/

相关文章:

docker - 使用 docker 创建时钟偏差

java - pom.xml(Maven 多模块项目)中的 <sonar.exclusions> 在本地工作但不在公司服务器上工作

Jenkins Docker 容器 - 403 请求中未包含有效的面包屑

python - 连接 postgres 和 Python

java - SSHJ - key 对登录到 EC2 实例

ruby-on-rails - Docker 容器未在端口 3000 上公开 Rails 应用程序

docker - 带参数的docker容器 `heroku run`命令返回 “not found”

shell - 将 Jenkins 控制台输出写入远程服务器中的文件

ruby-on-rails - Rails应用程序在远程计算机上运行命令

python - 无法使用 SIGKILL 杀死 docker 容器内的 pid 1