docker network access fixed IP address

Viewed 28

I need to access a physical device from a container on a windows host (running Docker desktop). The device has a fixed ip-address in a separate subnet (192.168.0.5/24). How to properly setup the network for the container (via docker run or docker-compose)?

I first thought of just opening the relevant port but for one, it is chosen by random (e.h. 52714, 63575) and for second if the port is open, I cannot reach the device. So I tried to fetch a ipvlan but in this configuration I am not reaching the container at all.

version: "3.8"

services:
  python-fastapi:
    container_name: fast_api
    build:
      context: Python
      dockerfile: Vision_fastAPI.Dockerfile
    ports:
      - "5001:5000"
    networks:
      - myVLan

networks:
  myVLan:
    driver: ipvlan
    driver_opts:
      parent: host
      ipvlan_mode: l2
    ipam:
      config:
      - subnet: 192.168.0.0/24

Actually, I was trying to reproduce a tutorial (from a Ubuntu host):

docker network create -d ipvlan --subnet=192.168.0.0/24 --ip-range=192.168.0.0/24 -o ipvlan_mode=l2 -o parent=enp11s0f1 myVLan

Obviously, I struggle with the parent option. I thought, I would be the physical ethernet adapter but I have no idea of the naming in windows (docker-compose doesn't accept names like "Ethernet 8" so I guess, I am getting something wrong here). It works with a docker network ("default") but just in the way that it doesn't produce an error.

The configuration of the ethernet adapter is the following:

Ethernet adapter Ethernet 8:

   Connection-specific DNS Suffix:
   Description . . . . . . . . . . . : Lenovo USB Ethernet #4
   Physical Address  . . . . . . . . : 3C-18-A0-52-43-C1
   DHCP Enabled  . . . . . . . . . . : no
   Autoconfiguration Enabled . . . . : Yes
   IPv4 Address  . . . . . . . . . . : 192.168.0.210(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . :
   NetBIOS over Tcpip  . . . . . . . : Enabled
1 Answers

Do absolutely nothing. Delete all of the networks: blocks in the Compose file. Connect to the external IP address as normal; Docker provides a network address translation (NAT) mechanism that will let you connect to the off-box service.

If you set up a Domain Name Service (DNS) server for your environment (highly recommended), make sure to use a fully-qualified domain name (FQDN) when you connect to the service, other-host.example.com. If you use a short name other-host then Docker will try to interpret that as a container name.

Related