Search code examples
dockerbashboot2docker

exporting DOCKER_HOST in .bashrc produces a different result to the same command in the terminal


Before I can use my docker container (using Boot2Docker on OSX) I always have to remember to enter

export DOCKER_HOST=tcp://$(boot2docker ip 2>/dev/null):2375

in my terminal, and naturally I often forget this.

So I figured I'd just add that line to my ~/.bashrc file but when I've done this and check the value of DOCKER_HOST it's tcp://192.168.42.43:4243 instead of tcp://192.168.42.43:2375.

Breaking it down:

  • boot2docker ip => "The VM's Host only interface IP address is: 192.168.59.103"
  • boot2docker ip 2 => "The VM's Host only interface IP address is: 192.168.59.103"
  • boot2docker ip 2>/dev/null => "192.168.59.103" (okay I sort of get that but I have no idea how that works, and I have no idea where the :4243 is coming from."

What's actually going on here and why is the port different?


Solution

  • Something else is setting that environment variable for you. Why are you dumping stderr from that command to /dev/null. Is some extra info coming to stderr?

    I would do

    export DOCKER_HOST="tcp://$(boot2docker ip 2>/dev/null):2375" ;
    echo "Docker Host is set to ${DOCKER_HOST}"
    

    For some debugging as it is set, then query the value at a later stage to see if something else is messing with it.