【问题标题】:Jenkins cannot curl to a http endpoint host on a docker containerJenkins 无法 curl 到 docker 容器上的 http 端点主机
【发布时间】:2021-04-02 01:49:12
【问题描述】:

我正在尝试构建一个 docker 容器并使用 jenkins 对同一个构建的容器运行我的集成测试。

我目前遇到的问题是我可以构建和运行容器,当我尝试对 http 端点进行 curl 时,我收到连接拒绝。所以我相信这与我的詹金斯奴隶配置有关。我已将 jenkins 用户添加到 wheel docker jenkins 组,当我运行记录为 jenkins 的 curl 命令时,它可以工作。但是当我从詹金斯运行它时,我收到了连接拒绝。

    JenkinsFile 
    sh "docker build -t my-service ."
    sh "docker rm -f my-service || true"
    sh "docker run -d -p 9091:5000 -p 1433:1433 --name=my-service my-service"
    sh "docker ps"
    sh "curl -v http://172.16.32.20:9091/api/products/"

詹金斯输出

+ curl -v http://172.16.32.20:9091/api/products/baggingoptions
* About to connect() to 172.16.32.20 port 9091 (#0)
*   Trying 172.16.32.20...
% Total    % Received % Xferd  Average Speed   Time    Time     Time  
 Current
                             Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     
  0* Connection refused
  * Failed connect to 172.16.32.20:9091; Connection refused
  * Closing connection 0
 curl: (7) Failed connect to 172.16.32.20:9091; Connection refused

从站信息:

Static hostname: **************************
     Icon name: computer-vm
       Chassis: vm
    Machine ID: 009cdec7fded4740be96692dfee788c0
       Boot ID: fe492def29c047bf910c213911fda980
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
   CPE OS Name: cpe:/o:centos:centos:7
        Kernel: Linux 3.10.0-514.26.2.el7.x86_64
  Architecture: x86-64

【问题讨论】:

  • 为什么要映射两个端口?您的服务在两个不同的端口(5000 和 1433)上运行?
  • 我的应用程序需要这两个端口

标签: curl docker jenkins centos


【解决方案1】:

如果您执行 docker run,服务器启动可能需要一些时间,但您会立即尝试连接。也可能的原因是防火墙阻止了请求,服务器的 IP 地址不是静态的或 docker 服务本身失败。没有足够的信息来得出结论性的答案。

【讨论】:

  • 这就是问题所在,谢谢。我增加了等待超时并且它起作用了
  • 我也成功地在服务器启动后休眠了几秒钟然后卷曲
【解决方案2】:

只需在执行 curl 之前添加延迟(或在 curl cmd 中添加重试):docker 不会这么快加载容器 :)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-25
    • 2017-04-11
    • 2023-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多