Skip to content

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

Description

@y7a8c9

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions