in local setup, can run ...
docker run --name myapp -e host=$(docker-machine ip default) --user root myapp
... , use $host
connect other container (e.g. 1 running mongodb).
however, in travis, docker-machine
not exist. thus, cannot put line in .travis.yml
.
how network ip?
the flag --link
adds entry /etc/hosts
ip address of specified running container
docker run --name myapp --link mongodb:mongodb myapp
however please note that:
the default
docker0
bridge network supports use of port mapping ,docker run --link
allow communications between containers indocker0
network. these techniques cumbersome set , prone error. while still available techniques, better avoid them , define own bridge networks instead.
another option using flag --add-host
if want add known ip address
docker run --name myapp --add-host mongodb:10.10.10.1 myapp
option 2
create network
docker network create --subnet=172.18.0.0/16 mynet123
run mongodb container assigning static ip
docker run --network mynet123 --ip 172.18.0.22 -d mongodb
add ip other container
docker run --network mynet123 --add-host mongodb:172.18.0.22 -d myapp
Comments
Post a Comment