gpt4 book ai didi

docker - CircleCI:配置在gcp上托管的Docker容器的测试

转载 作者:行者123 更新时间:2023-12-02 20:15:26 27 4
gpt4 key购买 nike

我正在使用CircleCI设置持续的部署过程,以Google Container Engine为目标。我正在关注this documentationthis example

我在这个阶段陷入困境:

test:
post:
- docker run -d -p 3000:3000 -e "SECRET_KEY_BASE=${SECRET_KEY}" eu.gcr.io/${PROJECT_NAME}/${MAIN_CONTAINER_NAME}:latest; sleep 10
- curl --retry 10 --retry-delay 5 -v http://localhost:3000

这是一个简单的测试,验证我的docker镜像是否能够响应http请求。我在 curl 后得到以下结果:
* Rebuilt URL to: http://localhost:3000/
* Hostname was NOT found in DNS cache
* Trying 127.0.0.1...
* connect to 127.0.0.1 port 3000 failed: Connection refused
* Failed to connect to localhost port 3000: Connection refused
* Closing connection 0
curl: (7) Failed to connect to localhost port 3000: Connection refused

curl --retry 10 --retry-delay 5 -v http://localhost:3000 returned exit code 7

如果我在本地shell中尝试该命令,则该命令有效。我在本地得到此结果:
* Rebuilt URL to: http://localhost:3000/
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 3000 (#0)
> GET / HTTP/1.1
> Host: localhost:3000
> User-Agent: curl/7.51.0
> Accept: */*
>
* Curl_http_done: called premature == 0
* Empty reply from server
* Connection #0 to host localhost left intact
curl: (52) Empty reply from server

我不知道这种差异的原因。

最佳答案

一种方法是首先使用名称启动容器:
docker run -d -p 3000:3000 -e "SECRET_KEY_BASE=${SECRET_KEY}" --name ${MAIN_CONTAINER_NAME} eu.gcr.io/${PROJECT_NAME}/${MAIN_CONTAINER_NAME}:latest; sleep 10
然后用以下运行的curl容器替换curl任务:
docker run --network container:${MAIN_CONTAINER_NAME} appropriate/curl --retry 10 --retry-delay 5 -v http://172.17.0.2
附加说明:
--network container:${MAIN_CONTAINER_NAME}-将curl容器附加到MAIN_CONTAINER_NAME容器的网络,默认情况下,其范围为172.17.0.0/16http://172.17.0.2-由于MAIN_CONTAINER_NAME是该Docker网络中创建的第一个容器,因此它将具有172.17.0.2 IP地址,其中主机位于.1上,而curl容器位于.3

关于docker - CircleCI:配置在gcp上托管的Docker容器的测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43778846/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com