如何解决Gitlab Piepline + docker:7无法连接到本地主机端口9000:连接拒绝
我是编写管道的新手,以下是我要运行的工作
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
请帮助我解决此问题,也帮助我理解错误。
解决方法
该错误消息表示在localhost:9000上没有任何运行。检查您的应用程序是否实际配置为在端口9000上运行,如果是,请尝试将curl请求推迟几秒钟,以允许应用程序初始化。
,我遇到了类似的问题。谷歌搜索后,我发现 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"
并且我的管道有效,希望我的回答对您有所帮助
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。