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

Access a service from the same ip:port in both a container and the host/lan (docker rootless) #332

Open
y7a8c9 opened this issue Dec 20, 2023 · 1 comment
Labels
question Further information is requested

Comments

@y7a8c9
Copy link

y7a8c9 commented Dec 20, 2023

Hello,

This is my first post on GitHub. I hope I've provided enough information, and that my issue is clearly articulated.

I'm working on a Docker rootless project and facing an issue with accessing a service from both another container and my host using the same IP and port. While I've managed to access it using my host's global (LAN) IP address, this isn't very convenient.

I'd prefer to access it through a local IP address.

Here's an example of my setup:

version: "3"

services:
  nginx:
    image: nginx
    ports:
      - 8080:80
    networks:
      cust_network:
        ipv4_address: 172.27.0.101

  cmdline:
    image: busybox
    networks:
      - cust_network

networks:
  cust_network:
    driver: bridge
    ipam:
      config:
        - subnet: 172.27.0.0/24

From my host, I can access the service using:

  • 172.17.0.1:8080 (the default bridge network for Docker)
  • 127.0.0.1:8080
  • 192.168.25.54:8080 (my computer's IP)

And from the 'cmdline' container in the same network, I can access it using:

  • 172.27.0.101
  • 192.168.25.54:8080 (my computer's IP)

What I want is to access it through an address such as 172.17.0.1:8080 or 172.23.0.1:8080.

Is this possible? If so, how can it be achieved? Alternatively, are there any tricks to accomplish something similar?

Thank you for your help!

@y7a8c9 y7a8c9 changed the title Access a service from the same ip:port in both a container and the host/lan in docker rootless Access a service from the same ip:port in both a container and the host/lan (docker rootless) Dec 20, 2023
@AkihiroSuda
Copy link
Member

172.17.0.1:8080 (the default bridge network for Docker)

In the case of Rootless Docker, this is not really accessible from the host.
But if you have a bridge for Rootful Docker, and let Rootless Docker bind on 0.0.0.0, the port is bound to the bridge's IP as well.

What I want is to access it through an address such as 172.17.0.1:8080 or 172.23.0.1:8080.

So, you can't use 172.17.0.1.
172.27.0.101 is the right IP to use.
Not sure what is 172.23.0.1.

@AkihiroSuda AkihiroSuda added the question Further information is requested label Dec 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants