Search code examples
dockerubuntugitlabubuntu-18.04vmware-player

Connect a docker's container port that is running inside an Ubuntu VM, with the VM's host machine network


I have a Docker running inside an Ubuntu-18.04 image (VMWare Player) which is hosted on a Windows PC. Docker has a container for Gitlab which I can access through localhost:4000 from my VM. The question is how can I access the very same Gitlab instance from my Windows PC? From my understanding there are two layers I need to connect. The first is the Docker with the VM host and the second is the VM host with the Windows host. I've tried creating a bridged connection between The Windows Host and the VM but I couldn't make it work. Please provide a detailed answer with steps if possible.


Solution

  • OK problem solved thanks to PanosMR.

    The solution for me was to set VM network as host-only. Then assign an Sub-net IP to the VM like 192.168.42.0 with a mask like 255.255.255.0.

    After that I went to see which IP my VM was assigned to. The IP was 192.128.42.128. Then on docker inside my Ubuntu VM I had set the Gitlab container --publish IP at the very same VM's IP plus the port.

    For example --publish 192.168.42.128:4000:80 and boom! When Gitlab container initiated I had access through my Windows PC on that IP.

    That was the simplest solution I've ever saw and also the only legit.