如何测试 testcontainers 使用的 podman 套接字 HTTP

How to test podman socket HTTP used by testcontainers

提问人:Gaël J 提问时间:11/16/2023 更新时间:11/16/2023 访问量:22

问:

在 Testcontainers (Java) 上下文中,我注意到 Testcontainers 由于某种原因无法与 podman 通信并挂起。

以下是我可以看到的调试日志:

[info] o.t.d.DockerClientProviderStrategy - Loaded org.testcontainers.dockerclient.RootlessDockerClientProviderStrategy from ~/.testcontainers.properties, will try it first
[debug] o.t.d.RootlessDockerClientProviderStrategy - $XDG_RUNTIME_DIR is not set.
[debug] o.t.d.RootlessDockerClientProviderStrategy - '/opt/gitlab-runner/.docker/run' does not exist.
[debug] o.t.d.DockerClientProviderStrategy - Trying out strategy: RootlessDockerClientProviderStrategy
[debug] o.t.s.c.g.d.c.c.AbstrDockerCmd - Cmd:
[debug] c.g.d.z.s.o.a.h.c.h.i.c.InternalHttpClient - ex-00000001: preparing request execution
[debug] c.g.d.z.s.o.a.h.c.h.p.RequestAddCookies - Cookie spec selected: strict
[debug] c.g.d.z.s.o.a.h.c.h.p.RequestAuthCache - Auth cache not set in the context
[debug] c.g.d.z.s.o.a.h.c.h.i.c.ProtocolExec - ex-00000001: target auth state: UNCHALLENGED
[debug] c.g.d.z.s.o.a.h.c.h.i.c.ProtocolExec - ex-00000001: proxy auth state: UNCHALLENGED
[debug] c.g.d.z.s.o.a.h.c.h.i.c.ConnectExec - ex-00000001: acquiring connection with route {}->unix://localhost:2375
[debug] c.g.d.z.s.o.a.h.c.h.i.c.InternalHttpClient - ex-00000001: acquiring endpoint (3 MINUTES)
[debug] c.g.d.z.s.o.a.h.c.h.i.i.PoolingHttpClientConnectionManager - ex-00000001: endpoint lease request (3 MINUTES) [route: {}->unix://localhost:2375][total available: 0; route allocated: 0 of 2147483647; total allocated: 0 of 2147483647]
[debug] c.g.d.z.s.o.a.h.c.h.i.i.PoolingHttpClientConnectionManager - ex-00000001: endpoint leased [route: {}->unix://localhost:2375][total available: 0; route allocated: 1 of 2147483647; total allocated: 1 of 2147483647]
[debug] c.g.d.z.s.o.a.h.c.h.i.i.PoolingHttpClientConnectionManager - ex-00000001: acquired ep-00000000
[debug] c.g.d.z.s.o.a.h.c.h.i.c.InternalHttpClient - ex-00000001: acquired endpoint ep-00000000
[debug] c.g.d.z.s.o.a.h.c.h.i.c.ConnectExec - ex-00000001: opening connection {}->unix://localhost:2375
[debug] c.g.d.z.s.o.a.h.c.h.i.c.InternalHttpClient - ep-00000000: connecting endpoint (3 MINUTES)
[debug] c.g.d.z.s.o.a.h.c.h.i.i.PoolingHttpClientConnectionManager - ep-00000000: connecting endpoint to unix://localhost:2375 (3 MINUTES)
[debug] c.g.d.z.s.o.a.h.c.h.i.i.DefaultHttpClientConnectionOperator - http-outgoing-0: connecting to localhost/127.0.0.1:2375
[debug] c.g.d.z.s.o.a.h.c.h.i.i.DefaultHttpClientConnectionOperator - http-outgoing-0: connection established
[debug] c.g.d.z.s.o.a.h.c.h.i.i.PoolingHttpClientConnectionManager - ep-00000000: connected http-outgoing-0
[debug] c.g.d.z.s.o.a.h.c.h.i.c.InternalHttpClient - ep-00000000: endpoint connected
[debug] c.g.d.z.s.o.a.h.c.h.i.c.MainClientExec - ex-00000001: executing GET /v1.32/info HTTP/1.1
[debug] c.g.d.z.s.o.a.h.c.h.i.c.InternalHttpClient - ep-00000000: start execution ex-00000001
[debug] c.g.d.z.s.o.a.h.c.h.i.i.PoolingHttpClientConnectionManager - ep-00000000: executing exchange ex-00000001 over http-outgoing-0
[debug] c.g.d.z.s.o.a.h.c.h.headers - http-outgoing-0 >> GET /v1.32/info HTTP/1.1
[debug] c.g.d.z.s.o.a.h.c.h.headers - http-outgoing-0 >> x-tc-sid: 17aa0133-17d2-48fb-8d9c-0a6466724e15
[debug] c.g.d.z.s.o.a.h.c.h.headers - http-outgoing-0 >> User-Agent: tc-java/1.19.1
[debug] c.g.d.z.s.o.a.h.c.h.headers - http-outgoing-0 >> Accept-Encoding: gzip, x-gzip, deflate
[debug] c.g.d.z.s.o.a.h.c.h.headers - http-outgoing-0 >> Host: localhost:2375
[debug] c.g.d.z.s.o.a.h.c.h.headers - http-outgoing-0 >> Connection: keep-alive
[debug] c.g.d.z.s.o.a.h.c.h.wire - http-outgoing-0 >> "GET /v1.32/info HTTP/1.1[\r][\n]"
[debug] c.g.d.z.s.o.a.h.c.h.wire - http-outgoing-0 >> "x-tc-sid: 17aa0133-17d2-48fb-8d9c-0a6466724e15[\r][\n]"
[debug] c.g.d.z.s.o.a.h.c.h.wire - http-outgoing-0 >> "User-Agent: tc-java/1.19.1[\r][\n]"
[debug] c.g.d.z.s.o.a.h.c.h.wire - http-outgoing-0 >> "Accept-Encoding: gzip, x-gzip, deflate[\r][\n]"
[debug] c.g.d.z.s.o.a.h.c.h.wire - http-outgoing-0 >> "Host: localhost:2375[\r][\n]"
[debug] c.g.d.z.s.o.a.h.c.h.wire - http-outgoing-0 >> "Connection: keep-alive[\r][\n]"
[debug] c.g.d.z.s.o.a.h.c.h.wire - http-outgoing-0 >> "[\r][\n]"

如何重现 testcontainers 完成的请求以排除故障?

这些请求是在 HTTP 中发出的,但通过 Unix 套接字发出。localhost:2375/v1.32/info

套接字 curl testcontainers podman

评论


答:

0赞 Gaël J 11/16/2023 #1

碰巧 cURL 支持使用以下命令通过 Unix 套接字进行查询:

curl -v --unix-socket /run/user/1000/docker.sock 'http://localhost:2375/v1.32/info'

就我而言,这有助于确定我的一台机器的 podman 设置不正确(由于所有权 root 与其他用户不正确),因为上述请求将挂在这台机器上,而所有其他机器都会立即回答。

评论

1赞 Richard Huxton 11/17/2023
curl 有大量用于测试 http(s) 的有用选项