How to get the IP address of a local host in a docker container?

I use docker and run using script. I want to change in one of the configurations with the host IP in docker.

#!/bin/bash
IP=$(echo `ifconfig eth0 2>/dev/null|awk '/inet addr:/ {print $2}'|sed   's/addr://'`)
echo Setting xwiki config IP
CONFIG=/xwiki/webapps/xwiki/WEB-INF/xwiki.cfg
sed -i -e "s/^xwiki.authentication.authhost=localhost*/xwiki.authentication.authhost= $IP/"  $CONFIG

/xwiki/start_xwiki.sh -f

I launch my docker with the following command.

docker run -t -i $EXPOSE_PORTS $IMAGE "$@"
+4
source share
2 answers

As stated in " How to get the docker host IP address from inside the docker container , you can directly access it from the container:

/sbin/ip route|awk '/default/ { print $3 }'

, , ( ) , IP- , 172.17.42.1, IP, 192.168.1.x( NAT)

IP- run --env <key>=<value>

-e "DOCKER_HOST=$(ip -4 addr show docker0 | grep -Po 'inet \K[\d.]+')

( IP-?")

OP Pawan Sharma :

docker0 host docker ip. eth0, IP- .

-e "DOCKER_HOST=$(ip -4 addr show eth0| grep -Po 'inet \K[\d.]+')
+5

docker run -it --net="host" IMAGE?

, . - , host ip?

+1

Source: https://habr.com/ru/post/1611425/


All Articles