Reputation: 4716
In my local setup, I can run ...
docker run --name myapp -e HOST=$(docker-machine ip default) --user root myapp
... and then use $HOST
to connect to any other container (e.g. one running mongodb).
However, in Travis, docker-machine
does not exist. Thus, I cannot simply put that line in my .travis.yml
.
How do I get the network IP?
Upvotes: 2
Views: 751
Reputation: 8711
The flag --link
adds an entry to /etc/hosts
with the ip address of the specified running container
docker run --name myapp --link mongodb:mongodb myapp
However please note that:
The default
docker0
bridge network supports the use of port mapping anddocker run --link
to allow communications between containers in thedocker0
network. These techniques are cumbersome to set up and prone to error. While they are still available to you as techniques, it is better to avoid them and define your own bridge networks instead.
Another option is using the flag --add-host
if you want to add a known ip address
docker run --name myapp --add-host mongodb:10.10.10.1 myapp
Create a network
docker network create --subnet=172.18.0.0/16 mynet123
Run mongodb container assigning an static ip
docker run --network mynet123 --ip 172.18.0.22 -d mongodb
Add that ip to the other container
docker run --network mynet123 --add-host mongodb:172.18.0.22 -d myapp
Upvotes: 1