使用IP连接到Docker容器 [英] Connect to docker container using IP

查看:344
本文介绍了使用IP连接到Docker容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行以下命令:

$ 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

我有一些Docker容器。
一旦运行了 django ,其他一个就运行了 postgres 和第三个弹性搜索。

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

当我运行 django 容器时,

# python manage.py runserver 0:8000

使用网站时可以正常工作:

And it is working when I use the site:

localhost:8000/

但是,当我使用时不可用: 192.168.99.100: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拒绝连接。尝试:检查连接

192.168.99.100 refused to connect. Try: Checking the connection

postgres 和<$的情况相同c $ c> elasticseach 容器。

为什么我的Docker容器未应用默认docker-machine ip code>?

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

推荐答案

听起来您没有告诉Docker与您的VM对话,并且您的容器是

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

要解决:


  1. 带上

  1. Bring down your containers

运行 $ eval $(docker-machine env default) 以下环境变量:

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"

这告诉Docker如何与您的VM对话。

This tells Docker how to talk to your VM.

旋转容器备份

这篇关于使用IP连接到Docker容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆