Answer the question
In order to leave comments, you need to log in
How to find out the real IP address of a client inside a docker container?
Good day everyone. Tell me how to find out the real ip of the client in the web server inside the docker container? Now in the docker ip logs, not the real client.
network_mode: host does not help, moreover, the server does not start at all in this case (listen tcp4 192.168.0.104:80: bind: cannot assign requested address, although everything is correct in the hosts file), but if you listen on localhost, then becomes inaccessible from the host and from the network in general.
Host has IP 192.168.0.104, docker has 172.17.32.1.
Hosts file:
192.168.0.104 ivankprod.ru
192.168.0.104 www.ivankprod.ru Docker
-compose.yml file:
version: '3.8'
services:
certbot:
container_name: ikpru_certbot
image: certbot/certbot
restart: unless-stopped
entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"
volumes:
- ./data/certbot:/etc/letsencrypt
tarantool:
container_name: ikpru_tarantool
image: tarantool/tarantool:2.8
environment:
TARANTOOL_PORT: ${DB_TARANTOOL_PORT:-3301}
TARANTOOL_USER_NAME: ${DB_TARANTOOL_USER:-nothing}
TARANTOOL_USER_PASSWORD: ${DB_TARANTOOL_PASSWORD:-nothing}
command: tarantool /usr/local/share/tarantool/app.lua
ports:
- "${DB_TARANTOOL_PORT:-3301}:${DB_TARANTOOL_PORT:-3301}"
volumes:
- ./tarantool/app:/usr/local/share/tarantool
- ./tarantool/data:/var/lib/tarantool
app:
container_name: ikpru_app
build: .
image: ivankprodru_app
restart: on-failure
env_file:
- ${STAGE_MODE:-prod}.env
command: bash -c "cd ./home/app && ./server"
ports:
- "${SERVER_PORT_HTTP:-80}:${SERVER_PORT_HTTP:-80}"
- "${SERVER_PORT_HTTPS:-443}:${SERVER_PORT_HTTPS:-443}"
volumes:
- ./build_${STAGE_MODE:-prod}:/home/app
- ./data/certbot:/etc/letsencrypt
links:
- tarantool:${DB_TARANTOOL_HOST:-tarantool}
depends_on:
- certbot
- tarantool
Answer the question
In order to leave comments, you need to log in
network_mode: host
in this case, it will help, you just need to remove something that prevents you from binding the port.
There is another option to put Nginx in front of this service and pass the real IP in the http header to the backend X-Real-IP
.
Something like this:
location /blablbla/ {
proxy_pass http://127.0.0.1:8080/blablabla/;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question