简体   繁体   English

Docker 容器的 IP - Virtualbox + Windows

[英]IP of Docker Container - Virtualbox + Windows

What IP address can I use when on Windows machines for an IP of a Docker Container running within a VM on Virtual Box?在 Windows 机器上,我可以使用哪个 IP 地址作为在 Virtual Box 上的 VM 中运行的 Docker 容器的 IP?

I have:我有:

  • Windows 10 Machine with Windows 10 机器与
  • Virtualbox installed with Ubuntu VM与 Ubuntu VM 一起安装的 Virtualbox
  • that has Docker installed安装了 Docker
  • and a container running with ports 80/443和一个运行端口 80/443 的容器

On the VM I can run docker commands and see container running在 VM 上,我可以运行 docker 命令并查看容器正在运行

vagrant@ubuntu-xenial:~$ docker ps
CONTAINER ID        IMAGE               COMMAND              CREATED             STATUS              PORTS                                      NAMES
e7a41b3edecd        nrel/api-umbrella   "api-umbrella run"   17 minutes ago      Up 17 minutes       0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp   api-umbrella
vagrant@ubuntu-xenial:~$

The IP of that container is:该容器的IP是:

vagrant@ubuntu-xenial:~$ docker inspect e7a41b3edecd | grep "IPAddress"
            "SecondaryIPAddresses": null,
            "IPAddress": "172.17.0.2",
                    "IPAddress": "172.17.0.2",
vagrant@ubuntu-xenial:~$

I can the ping IP 172.17.0.2 and curl http://172.17.0.2 on the VM itself.我可以在 VM 本身上 ping IP 172.17.0.2 并 curl http://172.17.0.2 But when trying http://172.17.0.2 on Windows machines I have not response.但是在 Windows 机器上尝试http://172.17.0.2时我没有响应。

QUESTION - What IP do I use from Windows machine to get at the Docker container running on the VM?问题- 我从 Windows 机器使用什么 IP 来获取在 VM 上运行的 Docker 容器?

In order to expose your docker IP to your host machine, you need to set your VM Network Settings into "Bridged Adapter".为了将您的 docker IP 公开给您的主机,您需要将您的 VM 网络设置设置为“桥接适配器”。

I use macOS but I think its the same in windows.我使用 macOS,但我认为它在 Windows 中是一样的。

在此处输入图片说明

After that, check your VM IP.之后,检查您的VM IP。 For example if your VM IP 192.168.30.100, and your docker run in port 8000. Now you can access your docker with IP 192.168.30.100:8000 from your host.例如,如果您的虚拟机 IP 为 192.168.30.100,并且您的 docker 运行在端口 8000。现在您可以使用 IP 192.168.30.100:8000 从您的主机访问您的 docker。

If you are using Windows with Ubuntu VM and inside the Ubuntu VM you are running Docker Containers, you will need to expose the ports that you can needed in your docker-compose file or when you are creating the cointainer for example如果您使用 Windows 和 Ubuntu VM,并且在 Ubuntu VM 中运行 Docker 容器,则需要公开您在 docker-compose 文件中或在创建 cointainer 时可能需要的端口

docker-compose.yml example: docker-compose.yml 示例:

version: '3.1'
services:

  rabbitmq:
    build:
      context: .
      dockerfile: Rabbit-Dockerfile
    container_name: broker
    restart: always
    environment:
      TZ: GMT
      RABBITMQ_DEFAULT_USER: rabbitIpi
      RABBITMQ_DEFAULT_PASS: ipitasks2018
    tty: true
    hostname: rabbit
    networks:
      celerynet:
        aliases:
          - rabbit
 ports: - 5672:5672 - 5671:5671 - 4369:4369 - 25672:25672 - 8181:15672
networks:
  celerynet:
    driver: bridge

docker run example: docker 运行示例:

docker run -d -p 80:80 --name webserver nginx

After you exposed the ports of your container in the Ubuntu VM, you will need to access to the ip of your Ubuntu VM with the port of your containers.在 Ubuntu VM 中公开容器的端口后,您需要使用容器的端口访问 Ubuntu VM 的 ip。

If you have a firewall on your ubuntu VM you will need to open the ports that your containers will used如果您的 ubuntu VM 上有防火墙,则需要打开容器将使用的端口

requirements:要求:

  • windows 7 Windows 7的

  • docker-toolbox码头工人工具箱

instructions:指示:

  1. Start the docker quickstart terminal启动 docker 快速启动终端
  2. SSH inside the host vm with docker-machine ssh default在主机 vm 中使用docker-machine ssh default
  3. Type the command ip addr输入命令ip addr
  4. The ip address will be listed:将列出 IP 地址:

在此处输入图片说明

For windows, Vagrant BOX If it Oracle Virtual Box对于 windows,Vagrant BOX 如果是 Oracle Virtual Box

Network - can be in NAT mode Port forwarding should be added as rule .. which is something like this and then can browse with http:\\localhost:3000 Oracle VM Network settings网络 - 可以处于 NAT 模式端口转发应该作为规则添加.. 就像这样,然后可以浏览 http:\\localhost:3000 Oracle VM 网络设置

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

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