简体   繁体   中英

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.

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. So I believe it is something to do with my jenkins slave configuration. I have added the jenkins user to wheel docker jenkins group and when i run the curl command logged as jenkins it works. But when i run it from jenkins I am getting a connection refuse.

    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. 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. There is not enough information to have a conclusive answer.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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