8
votes

What IP address can I use when on Windows machines for an IP of a Docker Container running within a VM on Virtual Box?

I have:

  • Windows 10 Machine with
  • Virtualbox installed with Ubuntu VM
  • that has Docker installed
  • and a container running with ports 80/443

On the VM I can run docker commands and see container running

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:

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. But when trying http://172.17.0.2 on Windows machines I have not response.

QUESTION - What IP do I use from Windows machine to get at the Docker container running on the VM?

4
The answers you've already gotten are both helpful. I'd advise you to never use the Docker-internal IP addresses for anything, and never use docker inspect to look them up: they're not routable in situations like what you're encountering and there are better ways to reach the containers.David Maze
Thank You @DavidMaze., what are these better ways? As still no success with any the answers. Thanks MelissaMelissa
Use docker run -p or the Docker Compose ports: directive (as in @BrayanCaldera's answer) and connect to the VM's IP address (as in @HanaAlaydrus's answer) on the published port.David Maze
ok thanks @DavidMaze with you now, was already using docker run -pMelissa

4 Answers

1
votes

requirements:

  • windows 7

  • docker-toolbox

instructions:

  1. Start the docker quickstart terminal
  2. SSH inside the host vm with docker-machine ssh default
  3. Type the command ip addr
  4. The ip address will be listed:

enter image description here

2
votes

In order to expose your docker IP to your host machine, you need to set your VM Network Settings into "Bridged Adapter".

I use macOS but I think its the same in windows.

enter image description here

After that, check your 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.

1
votes

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

docker-compose.yml example:

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 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.

If you have a firewall on your ubuntu VM you will need to open the ports that your containers will used

0
votes

For windows, Vagrant BOX If it 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