【问题标题】:Gitlab piepline + docker : (7) Failed to connect to localhost port 9000: Connection refuseGitlab pipeline + docker : (7) 无法连接到 localhost 端口 9000:连接拒绝
【发布时间】:2020-12-18 23:43:43
【问题描述】:

我是编写管道的新手,下面是我正在尝试运行的工作

test website:
  image: node
  stage: test
  script:
    - npm i
    - npm i -g gatsby-cli
    - gatsby serve &
    - sleep 3
    - curl "http://localhost:9000" | grep -q "Gatsby"

但它在日志下面的最后一步失败了

gatsby serve &
$ sleep 3
$ curl "http://localhost:9000" | grep -q "Gatsby"
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (7) Failed to connect to localhost port 9000: Connection refused
ERROR: Job failed: exit code 1

请帮我解决这个问题,也帮助我理解错误。

【问题讨论】:

    标签: git docker gitlab localhost gitlab-ci-runner


    【解决方案1】:

    错误消息表示 localhost:9000 上没有任何运行。检查您的应用程序是否实际配置为在端口 9000 上运行,如果是,请尝试将您的 curl 请求推迟几秒钟以允许应用程序初始化。

    【讨论】:

    • 如果可能的话,你能告诉我应该如何推迟它吗?
    • 看来你已经用 sleep 命令做到了。尝试增加 sleep 值并检查 serve 命令的输出是否有错误。
    【解决方案2】:

    我遇到了类似的问题。谷歌搜索后,我发现 gatsby 服务器没有足够的时间启动,所以我增加了睡眠时间。后来管道输出了不同的代码错误(23) Failed writing body,这里似乎脚本管道curl "http://localhost:9000" | grep -q "Gatsby"有问题。 这个answer 解释了为什么这样的管道程序会出现这个错误,所以我就这样结束了,

    test website:
      image: node
      stage: test
      script:
        - npm i
        - npm i -g gatsby-cli
        - gatsby serve &
        - sleep 10
        - curl "http://localhost:9000" | tac | tac | grep -q "Gatsby"
    

    我的管道工作正常,希望我的回答对您有所帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-12
      • 1970-01-01
      • 1970-01-01
      • 2019-01-07
      • 1970-01-01
      • 2017-11-09
      • 2019-10-20
      • 2021-09-08
      相关资源
      最近更新 更多