简体   繁体   English

Jenkins 无法卷曲到 docker 容器上的 http 端点主机

[英]Jenkins cannot curl to a http endpoint host on a docker container

I am trying to build a docker container and run my integration test against the same built container using jenkins.我正在尝试构建一个 docker 容器并使用 jenkins 对同一个构建的容器运行我的集成测试。

The issue i'm currently having is I can build and run the container and when I try to do a curl to the http end point i get a connection refuse.我目前遇到的问题是我可以构建和运行容器,当我尝试对 http 端点进行 curl 时,我收到连接拒绝。 So I believe it is something to do with my jenkins slave configuration.所以我相信这与我的 jenkins slave 配置有关。 I have added the jenkins user to wheel docker jenkins group and when i run the curl command logged as jenkins it works.我已将 jenkins 用户添加到wheel docker jenkins组,当我运行以 jenkins 记录的 curl 命令时,它可以工作。 But when i run it from jenkins I am getting a connection refuse.但是当我从 jenkins 运行它时,我收到了连接拒绝。

    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/"

Jenkins output詹金斯输出

+ 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

Slave info:奴隶信息:

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

If you do a docker run, it may take some time for the server to startup, but you immediately try to connect.如果您执行 docker run,服务器启动可能需要一些时间,但您会立即尝试连接。 Also possible causes are that a firewall blocks requests, the ip address of your server is not static or that the docker service itself fails.还可能的原因是防火墙阻止了请求、您服务器的 IP 地址不是静态的或 docker 服务本身失败。 There is not enough information to have a conclusive answer.没有足够的信息来得出结论性的答案。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM