Connect to docker container using IP

青春壹個敷衍的年華 提交于 2019-12-11 15:11:27

问题


I'm running the next commands:

$ docker-machine ls
NAME      ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER        ERRORS
default   *        virtualbox   Running   tcp://192.168.99.100:2376           v17.06.2-ce   

$ docker-machine ip default
192.168.99.100

And I have some docker containers. Once of the is running django, other one postgres and a third one elastic search.

When I'm running my django container with:

# python manage.py runserver 0:8000

And it is working when I use the site:

localhost:8000/

But, is not available when I use: 192.168.99.100:8000 There, I have the browser message:

This site can’t be reached

192.168.99.100 refused to connect. Try: Checking the connection

The same happens for the postgres and elasticseach container.

Why my docker container is not applying the default docker-machine ip ?


回答1:


It sounds like you have not told Docker to talk to your VM, and that your containers are running on your host machine.

To resolve:

  1. Bring down your containers

  2. Run $ eval "$(docker-machine env default)" which sets the following environment variables:

    export DOCKER_TLS_VERIFY="1"
    export DOCKER_HOST="tcp://x.x.x.x:2376"
    export DOCKER_CERT_PATH="/Users/<yourusername>/.docker/machine/machines/default"
    export DOCKER_MACHINE_NAME="default"
    

    This tells Docker how to talk to your VM.

  3. Spin containers back up



来源:https://stackoverflow.com/questions/46329209/connect-to-docker-container-using-ip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!