How to create network to communicate with other machines in the LAN

Expected behavior

I want to communicate with other machines in the LAN in the docker container

Actual behavior

Docker containers and other machine networks are not accessible

The following is the IP information of the host:
IP:192.168.40.199
Subnet mask:255.255.255.0
Default gatway:192.168.40.254

I want to specify a IP address(192.168.40.242) for my docker container, then the program in the docker container can communicate with other machines in the LAN

so i create a transparent network like this:

docker network create -d transparent --subnet=192.168.40.0/24 --gateway=192.168.40.254 -o com.docker.network.windowsshim.networkname=mytransparent -o com.docker.network.windowsshim.interface=“以太网” mytransparent

Then i start a container with :

docker run --rm -it --network=mytransparent --ip=192.168.40.242 server cmd

(“server” is my image )

I use ipconfig to view the IP configuration,here is the problem ,
image
its ip is not the one i specified, and it changs everytime i set ipconfig, but why?

Here is some information about the network i created
image
What does the local scope mean? I do not understand

And i also tried l2bridge network ,it still do not work
I think i need your help.How to solve this problem ,thanks advance.

Looks like Docker development team specifically, purposefully and forcefully DON’T WANT TO ALLOW it to happen. I managed to implement a couple of solutions, which worked as a charm, but as soon as you reboot the system looks like Docker detects the implementations and destroy the work and reinvent the network layers, then everything fails.

It is so simple in Linux and a HELL in Windows. Almost like if Docker Dev Team wants to make Windows version unusable by developers and small teams for simple solutions. Too bad, because the small guys are the ones who bring the solutions to the attention of the big guys, who eventually pay big money for it!!!

For decades I haven’t been as disappointed with a product as I am now with Docker. I am one advanced user they are definitively loosing, and with me hundreds of implementations in multiple clients to whom I will suggest anything else but Docker.

My suggestion is: quit Docker all along and forget about it. Simply go back to what DOES work: VirtualBox or VMWare. For decades they’ve been doing the job right and support what is needed, instead of forcefully block people from doing what they need.

It works for me. But the network host machine is connected to, must have promiscuous mode enabled and mac spoofing. Otherwise it won’t work. Could you also share the mytransparent configuration? While creating my network, is used the -o parent=<network_device> option.

First, let me apologize from being obnoxious in this reply, but I am tired of reading people saying that it can be done but no one respond when I ask for a “how to”…

It would be great if you could describe your process to make it work in Windows. I mean, create a custom network, build and attach containers to the custom network and access the containers from the host machine using their custom static IP addresses issued by you. Also important is to have the containers able to access and mount volumes in the host machine. Everything must work seemingly.

To be more specific: No port restriction or requirement! What I mean with that is: I want to have several containers with specific server configuration running LAMP Stack. All the containers will mount a volume that will point their “/var/www/html/” to the folder in the host machine where the source code is located at (yes, all containers will see and serve the same files). As each container has its own IP address, the port mapping should not (and cannot be) an issue or a requirement, which means I should be able to simply open my browser in the host and access the IP address of the container and the page referent to my source code will show.

Each container should also be able to access each other as if they were real machines. So, my LAMP stack servers should be able to see and access my MySQL Server (another container), and, if I need, the NodeJS Server (another container) and any other server in the same network or in a network where my NAT is configured to allow communication.

I can do it on Linux, no problem. It is actually fun to have it all set over a Linux Host. In Windows hosts, however, nothing works and a lot of stuff is blocked or reverted after boot. Under Windows, the communication among container and the host machine is stuck and limited to port mapping (which prevents me, among several things, from using the hosts’ file of the host machine to point a domain to each container).

Notwithstanding, mounting the volume in Windows has been a hell issue until the last update when it appears the problem was “resolved” (despite, time after time, the volume gets disconnected for no reason and you have to reboot the container).

The obnoxious part is that I honestly doubt you will be able to pull this trick and teach the world how to do that.

Even if I ask you to teach us how to work around this limitation by simply mounting the host folder from inside the container using CIFS (Samba), I am sure you would fail on that too, despite it is not an impossible task as the previous request.

Feel free to reply rubbering a functional solution to my face… I will actually be happy if it happens! :slight_smile: On the other hand, when you exhaust your knowledge trying to do it (yeah, it is possible, but it is a pain in the neck to make it right), feel free to ask for a “how to” mount the Samba from inside the container so you can see the answer os about to dismantle things that Docker put there to prevent it from being done (which is the main reason I am pissed with the Docker Development Team, because they are the ones makeing it NOT work!!!).

2 Likes