Docker Container unable to use Host Network

603 Views Asked by At

I'm trying to create a plex container in the "host" mode, the container is created without problems but is not able to obtain network connectivity. I'm running Ubuntu 22.0. I already flushed iptables, allowed port 32400 via ufw but docker ps shows no port information, and docker inspect shows "connection refused" errors.

~$docker ps 
CONTAINER ID   IMAGE                COMMAND   CREATED       STATUS                   PORTS     NAMES
9b30e966f0df   plexinc/pms-docker   "/init"   6 hours ago   Up 6 hours (unhealthy)             plex

~$docker inspect plex

        "Health": {
            "Status": "starting",
            "FailingStreak": 2,
            "Log": [
                {
                    "Start": "2023-08-21T11:33:29.030426144-04:00",
                    "End": "2023-08-21T11:33:29.160688826-04:00",
                    "ExitCode": 1,
                    "Output": "curl: (7) Failed to connect to localhost port 32400: Connection refused\n"
                }
            ]
        }

YML File:

version: "2.20"
services:
  plex:
    container_name: plex
    image: plexinc/pms-docker
    restart: unless-stopped
    network_mode: host

    environment:
      - TZ= ”America/New_York”
      - HOSTNAME=  "plexmediaserver"
      - PLEX_CLAIM= ”claim-ZpdRxxxxxxxxjnAR”
      - ADVERTISE_IP="http://192.168.1.25:32400/"
    volumes:
      - /mnt/vmstation/Plex/PlexData/PMS:/config
      - /mnt/vmstation/Plex/Transcode:/transcode
      - /mnt/vmstation/Plex/Media:/data
1

There are 1 best solutions below

1
Saleh On

It's because of the network_mode directive in your compose file. When you put as host, it will take the ip of your localhost. You have to set the network_mode to bridge network.

version: "2.20"
services:
  plex:
    container_name: plex
    image: plexinc/pms-docker
    restart: unless-stopped
    network_mode: bridge

    environment:
      - TZ= ”America/New_York”
      - HOSTNAME=  "plexmediaserver"
      - PLEX_CLAIM= ”claim-ZpdRxxxxxxxxjnAR”
      - ADVERTISE_IP="http://192.168.1.25:32400/"
    volumes:
      - /mnt/vmstation/Plex/PlexData/PMS:/config
      - /mnt/vmstation/Plex/Transcode:/transcode
      - /mnt/vmstation/Plex/Media:/data