4

I am using docker and run using script. I want to change in one of configuration with host machine IP address 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 run my docker with following command.

docker run -t -i $EXPOSE_PORTS $IMAGE "$@" 
2
  • What do you want to achieve? Commented Oct 13, 2015 at 12:51
  • @Smutje I want to pass local machine IP address to docker container. In my script $IP gives container address not my local host. Commented Oct 13, 2015 at 12:59

2 Answers 2

8

As mentioned in "How to get the ip address of the docker host from inside a docker container", you can directly access it from the container:

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

But, as commented, when you are using the docker bridge (default) for the containers, this will output the bridges IP like 172.17.42.1 rather than the host's IP such as 192.168.1.x (typical of an home NAT)

You can pass the actual IP as an environment variable with run --env <key>=<value>

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

(From "Is there an easy way to programmatically extract IP address?")

As the OP Pawan Sharma comments:

docker0 gives host docker ip. I used eth0, it gives my host ip.

-e "DOCKER_HOST=$(ip -4 addr show eth0| grep -Po 'inet \K[\d.]+') 
Sign up to request clarification or add additional context in comments.

4 Comments

thanks. docker0 gives host docker ip. I used eth0 it gives my host ip. Is this right or generic solution?
@PawanSharma OK. I have edited the answer accordingly and included your comment for more visiibillty.
This does not work for me on windows. I always get a 172.x.x.x IP but not the 10.0.75.X ip I'm looking for.
@Huber Strage: you could ask a new question with your exact configuration (OS, docker, version, ...)
1

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

but I'm not quite sure what you want to achive. Something like a application that should be accessable via host ip?

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.