简体   繁体   English

Docker主机ip在ubuntu上

[英]Docker host ip on ubuntu

Its baffling how one get host ip address on windows (boot2docker) by just issuing this command: docker-machine ip 令人困惑的是如何通过发出以下命令获取Windows(boot2docker)上的主机IP地址:docker-machine ip

But same doesn't work on ubuntu using same command. 但是使用相同的命令在ubuntu上同样不起作用。 It always says : "docker-machine: command not found" 它总是说:“docker-machine:command not found”

Any idea on why its not working? 为什么它不起作用的任何想法? or is there different command to find the host ip while running ubuntu as the host machine os and docker host? 或者在运行ubuntu作为主机os和docker主机时是否有不同的命令来查找主机ip?

Instead of using docker-machine commands you could use regular docker commands. 您可以使用常规的docker命令,而不是使用docker-machine命令。

For example if you run the following container 例如,如果您运行以下容器

docker run --name some-postgres -p 5432:5432 -d postgres

You can access the container through localhost in port 5432 or you can use docker inspect to find the containers IP 您可以通过端口5432中的localhost访问容器,也可以使用docker inspect来查找容器IP

docker inspect --format '{{ .NetworkSettings.IPAddress }}' some-postgres

If you need to install docker-machine, the installation instructions are on the release page . 如果需要安装docker-machine,则安装说明位于发布页面上 So for the 0.8 release, the install command is: 因此对于0.8版本,install命令是:

curl -L https://github.com/docker/machine/releases/download/v0.8.0/docker-machine-`uname -s`-`uname -m` >/usr/local/bin/docker-machine && \
  chmod +x /usr/local/bin/docker-machine

That command needs to be run as root, so sudo -s first if you are logged in as a user. 该命令需要以root身份运行,因此如果您以用户身份登录,则首先执行sudo -s Docker-machine isn't typically installed on Linux unless you're using it to spin up some development machines in the cloud since Docker itself is directly installed on the OS rather than as a VM running boot2docker. Docker-machine通常不安装在Linux上,除非您使用它来启动云中的某些开发机器,因为Docker本身直接安装在操作系统上,而不是作为运行boot2docker的VM。


Edit: if you just need your ip address on linux, there are a variety of solutions for a linux host. 编辑:如果你只需要你的Linux上的IP地址,有一个Linux主机的各种解决方案。 ip a is the quick method to list all the local interfaces and the associated addresses. ip a是列出所有本地接口和相关地址的快速方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM