How to run a Docker Container in a Host Network Mode

1

By using a docker compose, you can run a Docker container in a host network mode by defining network mode in a docker-compose file. With this configuration the docker container would run on the host network and utilise the host network port which would get exposed and defined during docker build.

And keep in mind the you don’t have to provide any ports in docker-compose file in a host network mode, otherwise it would generate an error. Here’s an example docker-compose file

version: "3.7"

services:
  example-service:
    image: example-image
    network_mode: "host"
    restart: always
    environment:
      - TZ=Australia/Melbourne
    volumes:
      - example-image-data1883:/data

volumes:
  example-image-data1883:
5/5 - (1 vote)

royal52
royal52

I’m a DevSecOps Software engineer by profession and a SEO hobbyist. I’m passionate about everything Software, including game development.

We will be happy to hear your thoughts

Leave a reply