OH2.2 - docker-compose vs docker - does not start

I have been running my openhab in dockers already for a long time but if just fails now :frowning:

Version 2.1-SNAPSHOT is working fine from docker-compose.

But version 2.2-SNAPSHOT gives an error when running via docker-compose:

Compose file (it was bigger, but trimmed it down to this and still fails):

version: '2.1'

services:
  openhab:
    image: 'openhab/openhab:2.2.0-snapshot-amd64'
    network_mode: "host"

Error:

openhab_1  | Launching the openHAB runtime...
openhab_1  |
openhab_1  |                           __  _____    ____
openhab_1  |   ____  ____  ___  ____  / / / /   |  / __ )
openhab_1  |  / __ \/ __ \/ _ \/ __ \/ /_/ / /| | / __  |
openhab_1  | / /_/ / /_/ /  __/ / / / __  / ___ |/ /_/ /
openhab_1  | \____/ .___/\___/_/ /_/_/ /_/_/  |_/_____/
openhab_1  |     /_/                        2.2.0-SNAPSHOT
openhab_1  |                                Build #1034
openhab_1  |
openhab_1  | Hit '<tab>' for a list of available commands
openhab_1  | and '[cmd] --help' for help on a specific command.
openhab_1  | Hit '<ctrl-d>' or type 'system:shutdown' or 'logout' to shutdown openHAB.
openhab_1  |
openhab_1  | Error in initialization script: /openhab/userdata/etc/shell.init.script: String index out of range: 0
openhab_1  | openhab> openhab2_openhab_1 exited with code 0

However running it with normal docker start command there is no problem at all, what am I missing…

docker run -it --name openhab --net=host openhab/openhab:2.2.0-snapshot-amd64

Thanks!

Try taking out the echo "export TERM=dumb" | tee -a ~/.bashrc from the Dockerfile, and rebuild.

@smar thanks, I tried but it does not seem to make a difference, any hint about the underlying problem you suspect?

The problem is also reported at: http://karaf.922171.n3.nabble.com/Karaf-in-Docker-td4050799.html and we recently updated Karaf (@Kai does it sound familiair to you?)

If I remove the stuff about the colors it does not give that error:

But it still terminates:

(composer) martinvw@elbrus:~/src/docker-compose/openhab2$ docker-compose up
Starting openhab2_openhab_1 ... 
Starting openhab2_openhab_1 ... done
Attaching to openhab2_openhab_1
openhab_1  | + set -euo pipefail
openhab_1  | Starting with openhab user id: 9001
openhab_1  | + IFS='
openhab_1  | 	'
openhab_1  | + NEW_USER_ID=9001
openhab_1  | + echo 'Starting with openhab user id: 9001'
openhab_1  | + id -u openhab
openhab_1  | + case ${OPENHAB_VERSION} in
openhab_1  | ++ ls -A /openhab/userdata
openhab_1  | + '[' -z 'cache
openhab_1  | config
openhab_1  | etc
openhab_1  | logs
openhab_1  | tmp' ']'
openhab_1  | ++ ls -A /openhab/conf
openhab_1  | + '[' -z 'html
openhab_1  | icons
openhab_1  | items
openhab_1  | persistence
openhab_1  | rules
openhab_1  | scripts
openhab_1  | services
openhab_1  | sitemaps
openhab_1  | sounds
openhab_1  | things
openhab_1  | transform' ']'
openhab_1  | + chown -R openhab:openhab /openhab
openhab_1  | + exec gosu openhab ./start.sh
openhab_1  | Launching the openHAB runtime...
openhab_1  | 
openhab_1  |                           __  _____    ____      
openhab_1  |   ____  ____  ___  ____  / / / /   |  / __ )     
openhab_1  |  / __ \/ __ \/ _ \/ __ \/ /_/ / /| | / __  | 
openhab_1  | / /_/ / /_/ /  __/ / / / __  / ___ |/ /_/ /      
openhab_1  | \____/ .___/\___/_/ /_/_/ /_/_/  |_/_____/     
openhab_1  |     /_/                        2.2.0-SNAPSHOT
openhab_1  |                                Build #1034   
openhab_1  | 
openhab_1  | Hit '<tab>' for a list of available commands
openhab_1  | and '[cmd] --help' for help on a specific command.
openhab_1  | Hit '<ctrl-d>' or type 'system:shutdown' or 'logout' to shutdown openHAB.
openhab_1  | 
openhab_1  | openhab@main()> WARNING: EventAdmin: Event Task Processing Interrupted. Events may not be recieved in proper order.
openhab2_openhab_1 exited with code 0

But sometimes without error

(composer) martinvw@elbrus:~/src/docker-compose/openhab2$ docker-compose up
Starting openhab2_openhab_1 ... 
Starting openhab2_openhab_1 ... done
Attaching to openhab2_openhab_1
openhab_1  | + set -euo pipefail
openhab_1  | + IFS='
openhab_1  | 	'
openhab_1  | + NEW_USER_ID=9001
openhab_1  | + echo 'Starting with openhab user id: 9001'
openhab_1  | + id -u openhab
openhab_1  | Starting with openhab user id: 9001
openhab_1  | + case ${OPENHAB_VERSION} in
openhab_1  | ++ ls -A /openhab/userdata
openhab_1  | + '[' -z 'cache
openhab_1  | config
openhab_1  | etc
openhab_1  | logs
openhab_1  | tmp' ']'
openhab_1  | ++ ls -A /openhab/conf
openhab_1  | + '[' -z 'html
openhab_1  | icons
openhab_1  | items
openhab_1  | persistence
openhab_1  | rules
openhab_1  | scripts
openhab_1  | services
openhab_1  | sitemaps
openhab_1  | sounds
openhab_1  | things
openhab_1  | transform' ']'
openhab_1  | + chown -R openhab:openhab /openhab
openhab_1  | + exec gosu openhab ./start.sh
openhab_1  | Launching the openHAB runtime...
openhab_1  | 
openhab_1  |                           __  _____    ____      
openhab_1  |   ____  ____  ___  ____  / / / /   |  / __ )     
openhab_1  |  / __ \/ __ \/ _ \/ __ \/ /_/ / /| | / __  | 
openhab_1  | / /_/ / /_/ /  __/ / / / __  / ___ |/ /_/ /      
openhab_1  | \____/ .___/\___/_/ /_/_/ /_/_/  |_/_____/     
openhab_1  |     /_/                        2.2.0-SNAPSHOT
openhab_1  |                                Build #1034   
openhab_1  | 
openhab_1  | Hit '<tab>' for a list of available commands
openhab_1  | and '[cmd] --help' for help on a specific command.
openhab_1  | Hit '<ctrl-d>' or type 'system:shutdown' or 'logout' to shutdown openHAB.
openhab_1  | 
openhab_1  | openhab@main()> openhab2_openhab_1 exited with code 0

This looks strange especially because it exits with code 0, meaning happy AFAIK and the other error is also found in particular when people state that they get that error when shutting down Karaf.

I think it may be something to do with jline and the way docker treats tty terminals. I had the same error and have now managed to work around it by (a) removing the dumb terminal environment as above and (b) adding a -t (which you already seem to have) in my docker run command.

Here’s my full docker run command, in case there is anything else in there that may be playing a part (e.g. privileged?):

docker run \
        --name openhab \
        --net=host \
        -u root \
        -e "OPENHAB_HTTP_PORT=7070" \
        -e "OPENHAB_HTTPS_PORT=8443" \
        -e "EXTRA_JAVA_OPTS=-Dgnu.io.rxtx.SerialPorts=/dev/zwave:/dev/rfx:/dev/mysensors:/dev/ttyACM0:/dev/ttyACM1:/dev/ttyUSB0:/dev/ttyUSB1:/dev/ttyUSB2" \
        --cap-add=NET_ADMIN \
        --cap-add=NET_RAW \
        -v /etc/localtime:/etc/localtime:ro \
        -v /etc/timezone:/etc/timezone:ro \
        -v /opt/openhab/conf:/openhab/conf \
        -v /opt/openhab/userdata:/openhab/userdata \
        -v /opt/openhab/addons:/openhab/addons \
        -v /opt:/opt \
        --privileged \
        -t -d  \
        --restart unless-stopped \
        openhab:latest

EDIT: Sorry, just re-read your original post and realised that you had it working with the docker run command and not the compose file. The problem you are having in the compose file is that you don’t have the -t argument. Try adding the line tty: true into your compose file.

2 Likes

Yes that was it!

I will create a PR to fix the example in openhab-docker later this week!

Thanks!