skip to Main Content

I want to know client_real_ip But always return 172.0.0.1 or My laptop_ip

How to solve ??

OS : m1 mac

–network host is not working

Here is my case

Client_ip : 111.111.1.1

MyLaptop_ip : 222.222.2.2

Docker_container_server_ip : 172.0.0.1

  1. The client will send a request to the container server

  2. Then the request will arrive at my laptop first and from my laptop it will be sent to the container.

  3. in container_server, request.client.host is always 172.0.0.1 or 222.222.2.2
    I don’t want this ip , I want to client_ip 111.111.1.1(real client ip)

I think we should be able to send the request coming to the laptop to the container as it is. So that Docker doesn’t convert it internally and send it

I think I need to tweak the docker settings, but I don’t know what to do.

2

Answers


  1. Host networking might help:

    Here is an example of a docker-compose.yml file:

    version: '3.4'
    
    services:
      web:
        build: .
        command: runserver
        env_file:
          - .env
        volumes:
          - 'static:/opt/app/static:rw'
        ports:
          - 8080:8080
        network_mode: host  # Add this
    volumes:
      static:
    

    A little update on your comment, please also consider this: container to host

    extra_hosts:
        - "host.docker.internal:host-gateway"
    
    Login or Signup to reply.
  2. It is because of the NAT that is done by Docker. Maybe this can help or you can also try https://docs.docker.com/network/host/.

    Note: Host networking mode only works on Linux Host. As for Docker for Mac and Windows has a small packaged Linux kernel on which it is actually run.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search