2

I would like to connect a windows and a linux container within the same network.

First I create a network (Docker for Windows is set to "Windows Containers"):

docker network create --driver nat mynet

The network is created and docker network ls lists the new network.

docker-compose.yml of the windows and the linux service contain:

version: "3"
services:
  ...
    networks:
      mynet: {}
networks:
  mynet:
    external: true

With docker-compose up the windows container starts fine, after "Switch to Linux Containers" and trying to start the linux container the following error is shown:

ERROR: Network mynet declared as external, but could not be found. Please create the network manually using docker network create mynet and try again.

Also docker network ls does not list the network anymore.

What would be the correct way to share a network between windows and linux?

flavio.donze
  • 7,432
  • 9
  • 58
  • 91

1 Answers1

2

Toggling the 'Switch to Linux Containers" option causes your Docker to switch contexts back and forth between a linux vm that Docker runs on top of, and a windows operating system.

When you do this, you're effectively switching to a different set of docker resources that are not aware of each other. They're on separate operating systems. Unfortunately, you can't do what you're trying to do with compose, since compose will always run on a single Daemon, and a single Daemon runs on a single operating system. But you could set up a linux vm of your own, install docker on it, and make a 2 node swarm consisting of your windows machine and your linux VM. That way you could run your linux containers on one, your windows containers on the other, and connect them through a network.

Charles Desbiens
  • 879
  • 6
  • 14