如何从ubuntu容器中获取localhost url?

时间:2017-09-01 05:20:40

标签: selenium docker localhost

我有一个运行ubuntu的容器,但是我无法忘记运行我的docker镜像的localhost。

例如,我使用运行docker的lenovo笔记本电脑。然后我登录我的笔记本电脑启动并运行一个ubuntu容器。当我进入ubuntu容器时,我无法忘记localhost url。有没有办法将容器连接到localhost?还有多少种方法可以通过docker容器连接到localhost。

这是我忘记时收到的错误消息

 let [negative,zero,positive] = counter([0,0,1,1,2,2]);

 if(! negative) alert("no negative ones but "+zero+" nulls");

在此先感谢,所有类似的问题都没有回答我的问题。

1 个答案:

答案 0 :(得分:0)

Docker for mac recently gained a docker.for.mac.localhost(17.06)。

但对于Windows,您可以尝试“How to get the IP address of the docker host from inside a docker container”中详述的一些选项,至少是:

 run --env <key>=<value>

运行容器时传递IP是一种简单的方法。

 run -e "DOCKER_HOST=$(ip -4 addr show docker0 | grep -Po 'inet \K[\d.]+')"

或者,来自“Insert Docker parent host ip into container's hosts file

docker run --add-host=dockerhost:`docker network inspect \
--format='{{range .IPAM.Config}}{{.Gateway}}{{end}}' bridge` [IMAGE]