1

I need to run containers from docker-compose in host network mode. For example, if I run single container, I write:

docker run --net=host my_image

How to do this part --net=host in docker-compose?

2 Answers 2

4

The equivalent in docker-comopose is network_mode: host see the documentation in: https://docs.docker.com/compose/compose-file/

Sign up to request clarification or add additional context in comments.

Comments

1

add directory network_mode of the networks section to your service definition in your docker-compose.yml

also, pay attention network_mode is incompatible with port_bindings:

version: '3.5'

services:
  server:
    image: custome image
    container_name: "sample"
    command: bash -c "python sample.py"
    
    network_mode: host

1 Comment

not working for swarm. there are is conflicts

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.