Unix-Sockets connection not working
See original GitHub issueUsing podman-py we cannot connect to a local unix-socket. Irrespective of how we communicate the protocol, it will always end up as http.
The following does not work, it will end up making an http-request to http://%2frun%2fpodman.sock/v4.0.0/libpod/version
instead of the unix-socket.
def podman_py():
from podman import PodmanClient
uri = "unix:///run/podman.sock"
with PodmanClient(base_url=uri) as client:
version = client.version() # fails
print("Release: ", version["Version"])
print("Compatible API: ", version["ApiVersion"])
print("Podman API: ", version["Components"][0]["Details"]["APIVersion"], "\n")
For comparison, the following, manual connection to the socket works:
def podman_requests_unixsocket():
import requests_unixsocket
url = "http+unix://%2frun%2fpodman.sock/v4.0.0/libpod/version"
with requests_unixsocket.Session() as session:
response = session.get(url)
response.raise_for_status()
version = json.loads(response.text)
print("Release: ", version["Version"])
print("Compatible API: ", version["ApiVersion"])
print("Podman API: ", version["Components"][0]["Details"]["APIVersion"], "\n")
My suspicion is that we are doing something wrong, or that something is lost in translation when hard-coding the protocol to http
and then mapping to UDSAdapter down the line.
We made some manual changes to podman-py that seem to do the trick (although they look wrong to me):
# Map supported schemes to Pool Classes
_pool_classes_by_scheme = {
"http": UDSConnectionPool,
"http+unix": UDSConnectionPool,
"http+ssh": UDSConnectionPool,
}
# Map supported schemes to Pool Key index generator
_key_fn_by_scheme = {
"http": functools.partial(_key_normalizer, _PoolKey),
"http+unix": functools.partial(_key_normalizer, _PoolKey),
"http+ssh": functools.partial(_key_normalizer, _PoolKey),
}
if self.base_url.scheme == "http+unix":
self.mount("http+unix://", UDSAdapter(self.base_url.geturl(), **adapter_kwargs))
uri = urllib.parse.ParseResult(
"http+unix",
self.base_url.netloc,
urllib.parse.urljoin(path_prefix, path),
self.base_url.params,
self.base_url.query,
self.base_url.fragment,
)
We are using version 4.0.0
Issue Analytics
- State:
- Created a year ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Unix socket connection not working · Issue #525 - GitHub
I managed to make it work by connecting to a public IP. Sockets did not work, now trying to use SSL, but when...
Read more >Unix domain socket client won't connect - Stack Overflow
The server code seems to be working fine, however when I try to connect the client, the call to connect() fails. Here is...
Read more >How to find other end of unix socket connection? - Server Fault
Here is an example showing an ssh-agent unix domain socket to which a ssh process has connected: $ sudo ss -a --unix -p...
Read more >UNIX domain sockets - IBM
UNIX domain sockets enable efficient communication between processes that are running on the same z/TPF processor. UNIX domain sockets support both stream- ...
Read more >B.3.2.2 Can't connect to [local] MySQL server
normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@cdoern PTAL
@awildturtok can you please paste the output you get when this fails? also, please run
systemctl start podman
to ensure the socket it listening and that the system service is using this socket.This most likely is not on our end, as I just fresh installed podman-py 4.2 and ran the test code, and it succeeded. I would assume the custom mounting of the socket is not right.