Gitlab Piepline + docker:(7)无法连接到本地主机端口9000:连接拒绝

时间:2020-08-30 18:38:15

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

我是编写管道的新手,以下是我要运行的工作

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

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

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:0)

我遇到了类似的问题。谷歌搜索后,我发现 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"

并且我的管道有效,希望我的回答对您有所帮助