compose icon indicating copy to clipboard operation
compose copied to clipboard

Host networking does not work with version 2 format

Open bobrik opened this issue 10 years ago • 9 comments

$ docker-compose --version
docker-compose version 1.6.0, build unknown
version: "2"

networks:
  default:
    external:
      name: host

services:
  huh:
    image: alpine:3.3
    command: sleep 3600
ERROR: Container cannot be disconnected from host network or connected to host network

I can't find how to make it work with the new version. If there is no way, then there should be one. If there is a way, it should be documented.

bobrik avatar Feb 07 '16 12:02 bobrik

https://docs.docker.com/compose/compose-file/#upgrading:91de898b5f5cdb090642a917d3dedf68 (see net -> network_mode)

https://docs.docker.com/compose/compose-file/#network-mode:91de898b5f5cdb090642a917d3dedf68

dnephin avatar Feb 07 '16 17:02 dnephin

Thanks!

bobrik avatar Feb 07 '16 18:02 bobrik

@dnephin Sorry about commenting on a closed issue - but I'm having exactly the same problem as @bobrik but I can't figure out what your response means. As far as I can tell from the official documentation (https://docs.docker.com/compose/compose-file/#/external), the code shown above should be correct, is it not?

skrysm avatar Aug 31 '16 15:08 skrysm

The host network is special. You have to use network_mode: host on the service

dnephin avatar Aug 31 '16 15:08 dnephin

Sorry for reopening this, but is there any way to add the host network under the networks tag. I need both a container to be both connected to a bridge network and the host one, so I cannot use the network_mode option.

mgangelov avatar Aug 11 '17 10:08 mgangelov

I have the same question. It would be great to get a response. Or if there is some other configuration that can achieve this goal.

bhairav13 avatar Sep 12 '17 19:09 bhairav13

@dnephin according to documentation on docker-compose network-mode is ignored.

This option is ignored when deploying a stack in swarm mode with a (version 3) Compose file.

svscorp avatar Nov 25 '17 18:11 svscorp

@bhairav13 , @mangelov95 ,

Did you find answer to your situation. We are having similar problem statement. We need to connect a container to both bridge and host networks.

Thanks

jayeshkul avatar Apr 07 '18 05:04 jayeshkul

has anyone found a solution to this problem? we are also having issues with it :(

tropxy avatar Jul 06 '18 18:07 tropxy