networking - how can I connect to a docker from the outside host machine (mac) -
i new dockers.
i have ran docker container mongo running (using boot2docker
)
docker run --name some-mongo -p 27017:27017 -d mongo
inside docker:
root@8e9b742c127a:/# mongo mongodb shell version: 3.0.2 connecting to: test server has startup warnings: 2015-05-12t08:49:56.130+0000 control [initandlisten] 2015-05-12t08:49:56.130+0000 control [initandlisten] ** warning: /sys/kernel/mm/transparent_hugepage/enabled 'always'. 2015-05-12t08:49:56.130+0000 control [initandlisten] ** suggest setting 'never' 2015-05-12t08:49:56.130+0000 control [initandlisten] 2015-05-12t08:49:56.130+0000 control [initandlisten] ** warning: /sys/kernel/mm/transparent_hugepage/defrag 'always'. 2015-05-12t08:49:56.130+0000 control [initandlisten] ** suggest setting 'never' 2015-05-12t08:49:56.130+0000 control [initandlisten] > show dbs local 0.078gb >
docker ps
container id image command created status ports names 8e9b742c127a mongo:latest "/entrypoint.sh mong hour ago hour 0.0.0.0:27017->27017/tcp some-mongo
now things little tricky since require network knowledge.
how connect out side?
tried:
mongo localhost:27017
docker inspect some-mongo | grep ipaddress "ipaddress": "172.17.0.12", mongo 172.17.0.12:27017
mongo 0.0.0.0:27017
mongo 10.0.0.12:27017
mongo 192.168.3.124:27017
native docker: (linux)
by exposing port host via -p 27017:27017
can access mongodb service via ip address of docker host itself.
say if docker host 192.168.0.1
use ip address.
see: binding container ports host , connect using network port mapping
non-native docker: (e.g: os x/windows)
update: above response docker on linux; if on os x via boot2docker need connect boot2docker virtual machine's ip address yhou can boot2docker
cli:
$ boot2docker ip 192.168.59.103
Comments
Post a Comment