2

What is the docker compose equivalent of running a docker container with network of container === host network ?

docker run --rm -d --network host --name my_nginx nginx

Basically, how to specify the --network host inside docker-compose

Ankit Sanghvi
  • 467
  • 5
  • 18

2 Answers2

1

Currently, I am running this by just specifying the port mappings from host to docker container, where I use the same port on both

eg :

version: '3.8'
services:
  api-server:
    build: '.'
    ports:
      - "8080:8080"
Ankit Sanghvi
  • 467
  • 5
  • 18
  • This is the correct approach. You shouldn't need host networking in most cases, and it doesn't work on non-Linux host OSes. – David Maze Apr 22 '22 at 10:02
1

You need to specify the network mode inside your service at docker-compose.yml. Add it like this:

version: '3.8'
services:
  network_mode: "host"
  api-server:
    build: '.'
Skatox
  • 4,237
  • 12
  • 42
  • 47
90linux
  • 134
  • 3