First try to run Openhab in a docker on Ubuntu

Because of limitation on my Synology NAS I bought a NUC with i3 processor and 16GB RAM
I installed Ubuntu and docker and created a yaml compose file
I can install and it shows as running.
But I can´t access it on port 8080
The yaml file
name: docker-compose.yml

version: '2.2'

services:
  openhab:
    image: "openhab/openhab:4.1.1"
    restart: always
    network_mode: host
    volumes:
      - "/etc/localtime:/etc/localtime:ro"
      - "/etc/timezone:/etc/timezone:ro"
      - "/home/mynuc/docker/openhab4.1.1/addons:/openhab/addons"
      - "/home/mynuc/docker/openhab4.1.1/conf:/openhab/conf"
      - "/home/mynuc/docker/openhab4.1.1/userdata:/openhab/userdata"
    environment:
      CRYPTO_POLICY: "unlimited"
      EXTRA_JAVA_OPTS: "-Duser.timezone=Europe/Amsterdam"
      OPENHAB_HTTP_PORT: "8080"
      OPENHAB_HTTPS_PORT: "8443"

volumes:
  openhab_addons:
    driver: local
  openhab_conf:
    driver: local
  openhab_userdata:
    driver: local

I install it with : docker compose up -d


What do I wrong? localhost:8080 is not working

Just on the first look it seems like your compose file is missing port maps to make the openhab service port available outside the docker container :thinking:

For comparison - here is my compose file:

version: "2.2"

services:
  openhab:
    image: "openhab/openhab:2.5.12"
    container_name: openhab
    restart: always
    network_mode: host
    volumes:
      - "/etc/localtime:/etc/localtime:ro"
      - "/etc/timezone:/etc/timezone:ro"
      - "${PWD}/openhab/addons:/openhab/addons"
      - "${PWD}/openhab/conf:/openhab/conf"
      - "${PWD}/openhab/userdata:/openhab/userdata"
    environment:
      OPENHAB_HTTP_PORT: "8080"
      OPENHAB_HTTPS_PORT: "8443"
      USER_ID: ${UID}
      GROUP_ID: ${GID}
      EXTRA_JAVA_OPTS: "-Duser.timezone=Europe/Berlin"
    ports:
      - "5007:5007"      
      - "8080:8080"
      - "8443:8443"
  influxdb:
    image: influxdb:1.8.4
    container_name: influxdb
    restart: always
    network_mode: host
    ports:
      - "8083:8083"
      - "8086:8086"
      - "8090:8090"
      - "25826:25826/udp"
      - "2003:2003"
    env_file:
      # Check the file to set default password!
      - "${PWD}/env.influxdb"
    volumes:
      - "/etc/localtime:/etc/localtime:ro"
      - "${PWD}/influxdb/data:/var/lib/influxdb/"
      - "${PWD}/influxdb/backup:/backups/"
  grafana:
    image: grafana/grafana:latest
    container_name: grafana
    restart: always
    network_mode: host
    user: "${UID}:${GID}"
    ports:
      - "3000:3000"
    env_file:
      - "${PWD}/env.grafana"
    volumes:
      - "/etc/localtime:/etc/localtime:ro"
      - "${PWD}/grafana/data:/var/lib/grafana/"
  frontail:
    image: "welteki/frontail-openhab:latest"
    container_name: "frontail"
    restart: always
    network_mode: host
    depends_on:
      - openhab
    volumes:
      - "${PWD}/openhab/userdata/logs:/var/log/openhab:ro"
    ports:
      - "9001:9001"
  homebridge:
    image: oznu/homebridge:latest
    container_name: homebridge
    restart: always
    network_mode: host
    volumes:
      - "${PWD}/homebridge:/homebridge"
    environment:
      - PGID=${UID}
      - PUID=${GID}
      - HOMEBRIDGE_CONFIG_UI=1
      - HOMEBRIDGE_CONFIG_UI_PORT=8081
    ports:
      - "8081:8081"

I hope you try to use the NUC IP instead of localhost in your browser? :slight_smile:
Does it show that it properly started in the log files?

This should be unnecessary if you use:

Sounds right - actually overlooked that I still have the line regarding network_mode included :sweat_smile:

And yes - the port mapping also becomes obsolete for OP as he also uses network mode host :thinking:

Hi @HenMus,

you can check on the host OS what proces is listening on port 8080 using the following command:

sudo netstat -tunlp | grep 8080
tcp6       0      0 127.0.0.1:8080          :::*                    LISTEN      1234929/java        
tcp6       0      0 192.168.0.65:8080       :::*                    LISTEN      1234929/java 

There you can see the IP address - I 1st recommend to try to connect to the IP - not the hostname to avoid potential problems with name resolution. If you do not see anything on port 8080, or 8443 then we need to check other things - but that’s a first step in my opinion.

I think this is not necessary, as you directly map to the host os filesystem in the volumes section.

Here my declaration - note, I use a customized image and a .env file to define some of the environment variables; but this should not make a dfference:

  openhab:
    depends_on:
      - location
      - frontail
      - frontail-scripts
      - frontail-error
      - influxdb
      - grafana
      - zigbee2mqtt
    container_name: ${COMPOSE_PROJECT_NAME}-server
    image: pgfeller/openhab:4.1.1-1
    # https://hub.docker.com/r/openhab/openhab 
    build:
      args:
        - version=4.1.1
      context: ../images/openhab
    restart: unless-stopped
    network_mode: host
    group_add:
      - tty
    volumes:
      - /etc/localtime:/etc/localtime
      - /etc/timezone:/etc/timezone
      - $_OPENHAB_CONF/ssh/openhab:/openhab/.ssh
      - $_OPENHAB_CONF/ssh/oh-user:/oh-user/.ssh
      - $_OPENHAB_ADDONS:/openhab/addons
      - $_OPENHAB_CONF:/openhab/conf
      - $_OPENHAB_USERDATA:/openhab/userdata
    devices:
      - /dev/serial/by-id/usb-0658_0200-if00:/dev/ttyUSB1
      - /dev/serial/by-id/usb-Prolific_Technology_Inc._USB-Serial_Controller_D-if00-port0:/dev/ttyUSB0
    environment:
      - CRYPTO_POLICY=unlimited
      - SSHPASS=$SSHPASS
      - EXTRA_JAVA_OPTS=${EXTRA_JAVA_OPTS} 
      - OPENHAB_HTTP_ADDRESS=192.168.0.65

From the .env file:

EXTRA_JAVA_OPTS="-Duser.timezone=Europe/Berlin -Dorg.jupnp.network.useInterfaces=eno1 -Dorg.jupnp.network.useAddresses=192.168.0.65"

I use visual studio code with the recommended docker extensions - this will help you to e.g. have a look at the logs and to open a shell inside the container; but there are other tools that provide good support as well … e.g. portainer.

with kind regards,
Patrik

showing nothing

This is shown

2024-02-04 14:45:01.199 [INFO ] [org.openhab.core.Activator          ] - Starting openHAB 4.1.1 (build Release Build)
2024-02-04 14:45:14.539 [WARN ] [org.openhab.core.net.NetUtil        ] - Found multiple local interfaces - ignoring 172.18.0.1
2024-02-04 14:45:14.542 [WARN ] [org.openhab.core.net.NetUtil        ] - Found multiple local interfaces - ignoring 192.168.65.6
2024-02-04 14:45:14.544 [WARN ] [org.openhab.core.net.NetUtil        ] - Found multiple local interfaces - ignoring 192.168.65.9
2024-02-04 14:45:15.792 [INFO ] [.core.model.lsp.internal.ModelServer] - Started Language Server Protocol (LSP) service on port 5007
2024-02-04 14:45:26.090 [INFO ] [e.automation.internal.RuleEngineImpl] - Rule engine started.

Ignoring is not a good thing :wink:. Did you copy the configuration from an other machine? If so the server might be configured to bind to a defined IP. Search the userdatadirectory if the config file contains the IP of the previous machine (the container should be stopped while you do this). Then replace the IP with 0.0.0.0 (you can configure to what interface to bind later again in the UI.

Start the container again and do the netstat thingy again …

It is a 100% clean installation. All directories were empty

Interesting :thinking: … It is strange that it finds more than one IP address for your machine (192.168.65.6 & 192.168.65.9). I wonder why that’s the case …

You can try to bind OH with the environment var as shown above - but I do not know to which address … do you have wired & wlan connection active? If so I recommend to disable wifi on the host and use the wired connect.

If that does not help we need to dig some more …

What do you get when you type ip a on the host (note: do not post the MAC’s here, only the rest of the info).

Also the this output might be interesting:

docker network ls
NETWORK ID     NAME           DRIVER    SCOPE
15c0b2c93f5e   bridge         bridge    local
42168d95b3b2   host           host      local
5a135460cb37   laptop_zwave   bridge    local
3ff621a56cdf   none           null      local

as well as

docker network inspect host
[
    {
        "Name": "host",
        "Id": "42168d95b3b23785c6b70fca8f61eb99d5758fbadca25a0c52d1c1c405025451",
        "Created": "2023-06-03T22:14:04.186695299+02:00",
        "Scope": "local",
        "Driver": "host",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": null
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {},
        "Options": {},
        "Labels": {}
    }
]

Edit:

Digged a big arround - and not sure if OPENHAB_HTTP_ADDRESSwill have an effect; but the following config file might be of interest userdate/org/openhab/network.config:

How are you trying to connect to port 8080? Are you connecting from the local docker host, or from a remote host?

Install netcat if necessary:
sudo apt-get install netcat

On the Ubuntu docker host, I’d try
nc -zv localhost 8080

On a remote host I’d try the same command:
Linux:
nc -zv localhost 8080

Windows Powershell:
Test-NetConnection -ComputerName IPADDR_HERE -Port 8080
i.e.
Test-NetConnection -ComputerName 192.168.250.128 -Port 8080

Check the Ubuntu firewall:
sudo ufw status

Create a rule if necessary:
sudo ufw allow 8080/tcp

What output are you getting from docker ps (or docker ps -a)?

OpenHAB tends to use a lot of different ports, and some bindings use additional ports, and so I just allocated a separate local IP to OpenHAB. I’m happy to listen to the purists rant about this being an anti-pattern for containers.

Here is the approach that I use:
docker network create lan -d ipvlan
–subnet=192.168.250.0/24
–gateway=192.168.250.1
-o ipvlan_mode=l2

Where my home subnet is 192.168.250.x/24

I run the container with a static IP:
docker run
–name openhab
–net=lan
–ip=192.168.250.128
-v /etc/localtime:/etc/localtime:ro
-v /etc/timezone:/etc/timezone:ro
-v /container-data/openhab/addons:/openhab/addons
-v /container-data/openhab/conf:/openhab/conf
-v /container-data/openhab/userdata:/openhab/userdata
-e “CRYPTO_POLICY=unlimited”
-e “EXTRA_JAVA_OPTS=-Duser.timezone=America/New_York”
-d
–restart=always
openhab/openhab:latest

So there are some troubleshooting steps and some food for thought steps.

Networking with docker can definitely be a little tricky!

Not sure if you‘ve seen this one, but on my end it worked exactly like this some weeks ago (I killed my system and luckily could follow my own step-by-step).

I run oh on a dedicated nuc sized pc (ASUS) running Ubuntu. I surmise that your nuc is dedicated to OH? I’ve had zero issues running OH installed with apt. Are you planning to run additional server apps? I don’t see the value of docker in a dedicated box

yes

mynuc@mynuc-desktop:~$ nc -zv localhost 8080
nc: connect to localhost (127.0.0.1) port 8080 (tcp) failed: Connection refused

udo apt-get install netcat-openbsd
was already installed

Status: inactive

Not needed

Can this be the problem?

There is no IP address connected to port 8080

netstat -vatn
tcp        0      0 0.0.0.0:8000            0.0.0.0:*               LISTEN