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

Server fails to bind localhost in container #209

Open
Hanaasagi opened this issue Sep 15, 2023 · 0 comments
Open

Server fails to bind localhost in container #209

Hanaasagi opened this issue Sep 15, 2023 · 0 comments

Comments

@Hanaasagi
Copy link

From oven-sh/bun#5315

Reproduce

  1. Edit examples/http_server.c

struct us_listen_socket_t *listen_socket = us_socket_context_listen(SSL, http_context, 0, 3000, 0, sizeof(struct http_socket));

change to bind localhost:3000

        struct us_listen_socket_t *listen_socket = us_socket_context_listen(SSL, http_context, "localhost", 3000, 0, sizeof(struct http_socket));
  1. Create a container using the debian:sid-slim image and then run the http_server. (docker has not been configured for IPv6 stack)
root@5b4095ebc3eb:/tmp/uSockets# ./http_server
Failed to listen!
root@5b4095ebc3eb:/tmp/uSockets# cat /etc/hosts
127.0.0.1       localhost
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.2      5b4095ebc3eb
root@5b4095ebc3eb:/tmp/uSockets# vim /etc/hosts  # Remove `::1     localhost ip6-localhost ip6-loopback`
root@5b4095ebc3eb:/tmp/uSockets# ./http_server  # works now
Listening on port 3000...
^C

The server fails to bind, but if you remove ::1 from /etc/hosts, it starts successfully. It binds 127.0.0.1 now.

Regarding why there is still ::1 record present in the container even though IPv6 is not configured, please see moby/moby#35954

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

No branches or pull requests

1 participant