{"id":6633,"date":"2019-10-10T20:25:57","date_gmt":"2019-10-10T18:25:57","guid":{"rendered":"https:\/\/michlstechblog.info\/blog\/?p=6633"},"modified":"2019-10-11T11:49:59","modified_gmt":"2019-10-11T09:49:59","slug":"openhab-install-openhab-from-docker","status":"publish","type":"post","link":"https:\/\/michlstechblog.info\/blog\/openhab-install-openhab-from-docker\/","title":{"rendered":"Openhab: Install and run openhab from a docker image"},"content":{"rendered":"<div class=\"twoclick_social_bookmarks_post_6633 social_share_privacy clearfix 1.6.4 locale-en_US sprite-en_US\"><\/div><div class=\"twoclick-js\"><script type=\"text\/javascript\">\/* <![CDATA[ *\/\njQuery(document).ready(function($){if($('.twoclick_social_bookmarks_post_6633')){$('.twoclick_social_bookmarks_post_6633').socialSharePrivacy({\"services\":{\"flattr\":{\"uid\":\"Michl\",\"status\":\"on\",\"the_title\":\"Openhab%3A%20Install%20and%20run%20openhab%20from%20a%20docker%20image\",\"the_excerpt\":\"Hi%2C%0D%0A%0D%0Athis%20port%20describes%20how%20to%20quickly%20install%20an%20openhab%20instance%20from%20a%20docker%20image.%20In%20this%20example%20Openhab%20runs%20under%20user%2Fgroup%20openhab%20and%20the%20network%20of%20the%20docker%20container%20is%20connected%20to%20the%20host%20interface.%0D%0A%0D%0ABefore%20starting%20checkout%20the%20install%20docker%20post%20to%20get%20the%20system%20ready%20for%20hosting%20openhab.%0D%0A%20%28more%26hellip%3B%29\",\"txt_info\":\"2 clicks for more data protection:\\r\\n\\r\\nOnly when you click here, the button will be come active and you can send your recommendation to Flattr. When activating, data are transmitted to third parties. \",\"perma_option\":\"off\"}},\"txt_help\":\"When you activate these fields by clicking, information to Flattr may be transferred abroad, and probably may also stored there.\",\"settings_perma\":\"Enable permanently and accept data transmission. \",\"info_link\":\"http:\\\/\\\/www.heise.de\\\/ct\\\/artikel\\\/2-Klicks-fuer-mehr-Datenschutz-1333879.html\",\"uri\":\"https:\\\/\\\/michlstechblog.info\\\/blog\\\/openhab-install-openhab-from-docker\\\/\",\"post_id\":6633,\"post_title_referrer_track\":\"Openhab%3A+Install+and+run+openhab+from+a+docker+image\",\"display_infobox\":\"on\"});}});\n\/* ]]> *\/<\/script><\/div><p>Hi,<\/p>\n<p>this port describes how to quickly install an openhab instance from a docker image. In this example Openhab runs under user\/group openhab and the network of the docker container is connected to the host interface.<\/p>\n<p>Before starting checkout the install <a href=\"https:\/\/michlstechblog.info\/blog\/debian-install-docker\/\">docker post<\/a> to get the system ready for hosting openhab.<br \/>\n<!--more--><br \/>\n<!--https:\/\/www.openhab.org\/docs\/installation\/docker.html--><br \/>\nCreate the user and group openhab<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev ~ # useradd -r -s \/sbin\/nologin openhab\r\nroot@debdev ~ # usermod -a -G openhab openhab\r\n<\/pre>\n<p>Create folders for holding the config on the host system ant not inside the container.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev ~ # mkdir -p \/opt\/openhab\/conf\r\nroot@debdev ~ # mkdir -p \/opt\/openhab\/userdata\r\nroot@debdev ~ # mkdir -p \/opt\/openhab\/addons\r\nroot@debdev ~ # chown -R openhab:openhab \/opt\/openhab\r\n<\/pre>\n<p>Get UID\/GID<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev ~ # export USER_ID=$(egrep '^openhab' \/etc\/passwd|awk -F: '{print $3}')\r\nroot@debdev ~ # export GROUP_ID=$(egrep '^openhab' \/etc\/group|awk -F: '{print $3}')\r\n<\/pre>\n<p>If you are behind a proxy and have no direct connection to the Internet, configure the proxy server. <\/p>\n<p>Create a config directory for the docker service<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev ~ # mkdir \/etc\/systemd\/system\/docker.service.d\r\n<\/pre>\n<p>Create a file <strong>\/etc\/systemd\/system\/docker.service.d\/http-proxy.conf<\/strong><br \/>\n<code><br \/>\n[Service]<br \/>\nEnvironment=\"HTTP_PROXY=http:\/\/192.168.254.254:888\"<br \/>\nEnvironment=\"HTTPS_PROXY=http:\/\/192.168.254.254:888\"<br \/>\nEnvironment=\"NO_PROXY=localhost,127.0.0.0\/8\"<br \/>\n<\/code><br \/>\nand <strong>~\/.docker\/config.json<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n{\r\n &quot;proxies&quot;:\r\n {\r\n   &quot;default&quot;:\r\n   {\r\n     &quot;httpProxy&quot;: &quot;http:\/\/192.168.254.254:888&quot;,\r\n     &quot;httpsProxy&quot;: &quot;http:\/\/192.168.254.254:888&quot;,\r\n     &quot;noProxy&quot;: &quot;localhost&quot;\r\n   }\r\n }\r\n}\r\n<\/pre>\n<p>Reload config <\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev ~ # systemctl daemon-reload\r\nroot@debdev ~ # systemctl show --property Environment docker\r\nroot@debdev ~ # systemctl restart docker\r\n<\/pre>\n<p>To select the version you want to start look at <a href=\"https:\/\/hub.docker.com\/r\/openhab\/openhab\/tags\" rel=\"noopener noreferrer\" target=\"_blank\">docker hub<\/a> for all startable images and tags<\/p>\n<p>Run openhab. This one is for version 2.5.0-M3 on Standard PC Hardware amd64. <strong>-d<\/strong> means openhab detaches from the console and runs in background. For testing purposes omit the -d switch then you see all output messages at the console.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev ~ # docker run \\\r\n        --name openhab-2.5.0-M3 \\\r\n        --net=host \\\r\n        -v \/etc\/localtime:\/etc\/localtime:ro \\\r\n        -v \/etc\/timezone:\/etc\/timezone:ro \\\r\n        -v \/opt\/openhab\/conf:\/openhab\/conf \\\r\n        -v \/opt\/openhab\/userdata:\/openhab\/userdata \\\r\n        -v \/opt\/openhab\/addons:\/openhab\/addons\\\r\n        -d \\\r\n        -e OPENHAB_HTTP_PORT=8080 \\\r\n        -e OPENHAB_HTTPS_PORT=8443 \\\r\n        -e USER_ID=$USER_ID \\\r\n        -e GROUP_ID=$GROUP_ID \\\r\n        --restart=always \\\r\n         openhab\/openhab:2.5.0.M3-amd64-debian \r\n<\/pre>\n<p>If you are behind a proxy, pass the proxy in the run command by the EXTRA_JAVA_OPTS environment variable to the docker container<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n...\r\n-e OPENHAB_HTTP_PORT=8080 \\\r\n-e OPENHAB_HTTPS_PORT=8443 \\\r\n-e EXTRA_JAVA_OPTS=&quot;-Dhttp.proxySet=true -Dhttp.proxyHost=192.168.254.254 -Dhttp.proxyPort=888 -Dhttps.proxySet=true -Dhttps.proxyHost=192.168.254.254 -Dhttps.proxyPort=888&quot; \\\r\n-e USER_ID=$USER_ID \\\r\n...\r\n<\/pre>\n<p>Get a shell within the container<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev ~ # docker exec -it openhab-2.5.0-M3 sh -c &quot;\/bin\/bash&quot;\r\n<\/pre>\n<p>Start the openhab command line (Karaf console) within the container<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev ~ # docker exec -it openhab-2.5.0-M3 sh -c &quot;\/openhab\/runtime\/bin\/client&quot;\r\nLogging in as openhab\r\n\r\n                          __  _____    ____\r\n  ____  ____  ___  ____  \/ \/ \/ \/   |  \/ __ )\r\n \/ __ \\\/ __ \\\/ _ \\\/ __ \\\/ \/_\/ \/ \/| | \/ __  |\r\n\/ \/_\/ \/ \/_\/ \/  __\/ \/ \/ \/ __  \/ ___ |\/ \/_\/ \/\r\n\\____\/ .___\/\\___\/_\/ \/_\/_\/ \/_\/_\/  |_\/_____\/\r\n    \/_\/                        2.5.0.M3\r\n                               Milestone Build\r\n<\/pre>\n<p>Open a browser and connect to port 8080<br \/>\n<code><br \/>\nhttp:\/\/yourIPAddress:8080<br \/>\n<\/code><\/p>\n<p>Review logs by<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev ~ # docker logs openhab-2.5.0-M3\r\n<\/pre>\n<p>Stopping and starting the container<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev ~ # docker stop openhab-2.5.0-M3\r\nroot@debdev ~ # docker start openhab-2.5.0-M3\r\n<\/pre>\n<p>Have fun \ud83d\ude42<\/p>\n<p>Michael<\/p>\n<p>Reference: <a href=\"https:\/\/www.openhab.org\/docs\/installation\/docker.html\" rel=\"noopener noreferrer\" target=\"_blank\">OpenHAB<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, this port describes how to quickly install an openhab instance from a docker image. In this example Openhab runs under user\/group openhab and the network of the docker container is connected to the host interface. Before starting checkout the install docker post to get the system ready for hosting openhab.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[870,1314,1377],"tags":[1379,1373,119,224,1378],"class_list":["post-6633","post","type-post","status-publish","format-standard","hentry","category-debian","category-docker","category-openhab","tag-behind-proxy","tag-docker","tag-install","tag-linux-2","tag-openhab"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/6633","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/comments?post=6633"}],"version-history":[{"count":14,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/6633\/revisions"}],"predecessor-version":[{"id":6648,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/6633\/revisions\/6648"}],"wp:attachment":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/media?parent=6633"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/categories?post=6633"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/tags?post=6633"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}