Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update index.md #1650

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Update index.md #1650

wants to merge 1 commit into from

Conversation

hangonlyra
Copy link

Update Lambda troubleshooting to add workaround for Podman on MacOS

Update Lambda troubleshooting to add workaround for Podman on MacOS
Copy link

github-actions bot commented Feb 7, 2025

⚡️ Deploying PR Preview...

Copy link
Member

@HarshCasper HarshCasper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi – Thanks for adding the patch! However, we have a dedicated Podman page here: https://docs.localstack.cloud/references/podman/

Is the information available on the page not enough to fix the issue? Let us know. In any case, we might need to move this information into the Podman docs to make sure that we have such workarounds documented.

@hangonlyra
Copy link
Author

Hi – Thanks for adding the patch! However, we have a dedicated Podman page here: https://docs.localstack.cloud/references/podman/

Is the information available on the page not enough to fix the issue? Let us know. In any case, we might need to move this information into the Podman docs to make sure that we have such workarounds documented.

Hi!

The information on the Podman page does not work on MacOS. My hypothesis is that Podman on MacOS involves running a Linux VM which actually runs the Podman runtime. The Docker/Podman Unix socket lives in that VM and is mapped into the MacOS host. However, when we map the Unix socket using/var/run/docker:/var/run/docker from the MacOS host into the Localstack container, something doesn't translate correctly and the socket doesn't work from inside the Localhost container.

This can be demonstrated by mapping a directory on the MacOS host into the Localstack container. Then on the MacOS side run a Python script like:

import socket
import os

socket_path = 'test.socket'

# Remove the socket file if it exists
if os.path.exists(socket_path):
    os.remove(socket_path)

# Create and bind the Unix socket
server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
server.bind(socket_path)
server.listen(1)

print(f"Listening on {socket_path}...")

while True:
    connection, _ = server.accept()
    print("Connection received")
    while True:
        data = connection.recv(1024)
        if not data:
            break
        print(f"Received: {data.decode('utf-8')}")
    connection.close()

Then from the Localstack container run this Python script:

import socket

socket_path = 'test.socket'

# Create a Unix socket and connect to the server
client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
client.connect(socket_path)

# Send a message
message = "Hello from Python!"
client.sendall(message.encode('utf-8'))

# Close the socket
client.close()

You will get:

Traceback (most recent call last):
  File "/run/podman/test.py", line 7, in <module>
    client.connect(socket_path)
ConnectionRefusedError: [Errno 111] Connection refused

However, if you were to run the listener script from the Localhost container, the call will succeed and it will print out

Connection received
Received: Hello from Python!

I don't know the specific mechanism that's failing and I'm not certain this is specific to Podman (I seem to recall something similar happening with Docker Desktop on MacOS).

I think in general having an Unix socket in a Linux VM getting shared with the MacOS host and then shared again back into a container is going to be problematic.

To get around all of this, we can have Localstack get access to the Docker/Podman socket via TCP instead of Unix socket. Using socat is probably the most straight forward way or create a new remote connection in Podman that is pure TCP in addition to the SSH connection Podman creates by default.

Let me know if I should move the doc changes into the Podman section instead. I think that's a pretty good suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants