{"id":35,"date":"2022-02-10T12:49:06","date_gmt":"2022-02-10T12:49:06","guid":{"rendered":"https:\/\/www.wientzek.ch\/?p=35"},"modified":"2022-02-10T12:50:20","modified_gmt":"2022-02-10T12:50:20","slug":"dockerize-it","status":"publish","type":"post","link":"https:\/\/www.wientzek.ch\/?p=35","title":{"rendered":"Dockerize it!"},"content":{"rendered":"\n<p>The shell script working on a cron, with all the packages I now have installed on the system, and with some distributed configuration items&#8230; I made a Docker Image with the little stuff I have.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>FROM ubuntu:latest\nRUN apt-get update \\\n\t&amp;&amp; apt-get install -y ocrmypdf \\\n\t&amp;&amp; apt-get install tesseract-ocr-deu \\\n\t&amp;&amp; apt-get install -y imagemagick \\\n\t&amp;&amp; apt-get install -y cron\nRUN groupadd -g 1001 scanner \\\n        &amp;&amp; useradd -rm -d \/home\/scanner -s \/bin\/bash -g 1001 -u 1001 scanner\nWORKDIR \/home\/scanner\nCOPY --chown=scanner:scanner . .\nVOLUME \/home\/scanner\/archive\nVOLUME \/home\/scanner\/scanner\nRUN crontab -l | { cat; echo \"* * * * * timeout 1h flock -n \/home\/scanner\/apps\/lock\/translateNewFiles.lock su scanner -c \/home\/scanner\/apps\/scripts\/translateNewFiles.sh\"; } | crontab -\nCMD &#091;\"cron\", \"-f\"]\n\n<\/code><\/pre>\n\n\n\n<p>Behold, the Dockerfile. It would have worked out of the box, but&#8230; there is of course on thing in there that is not okay, the user management. I want to really have a &#8220;scanner&#8221; user on the system which writes all the files of our project. After a lot of failed attempts, the cron is running as root in the container and the translateNewfiles.sh is executed with the scanner user, where at the moment the user is hardcoded in uid and gid matching the outside user. I should change that.<\/p>\n\n\n\n<p>The data store is on the outside, just directories mounted in.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>version: \"3.3\"\nservices:\n  dochauser:\n    build: .\n    volumes:\n      - \/home\/scanner\/dochauser_mount\/archive:\/home\/scanner\/archive\n      - \/home\/scanner\/dochauser_mount\/scanner:\/home\/scanner\/scanner<\/code><\/pre>\n\n\n\n<p>Which means the docker-compose.yml looks like this and is quite simple for my tests.<\/p>\n\n\n\n<p>This will not be the nicest Docker Image ever created, but it works for me for the moment.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Oh shit, why do I get an access denied error trying to stop my own container?<\/p><cite>&#8211; All Ubuntu Server LTS users ever? <\/cite><\/blockquote>\n\n\n\n<p>i don&#8217;t know if this is common, but I had to remove docker-compose and docker and snap and apparmor and install everything freshly via apt-get. Now the system feels stable. But I had a bit of hate for this basic workflow not to go properly for me in Ubuntu Linux.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The shell script working on a cron, with all the packages I now have installed on the system, and with some distributed configuration items&#8230; I made a Docker Image with the little stuff I have. Behold, the Dockerfile. It would have worked out of the box, but&#8230; there is of course on thing in there &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"https:\/\/www.wientzek.ch\/?p=35\"> <span class=\"screen-reader-text\">Dockerize it!<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","footnotes":""},"categories":[4],"tags":[],"class_list":["post-35","post","type-post","status-publish","format-standard","hentry","category-dochauser"],"_links":{"self":[{"href":"https:\/\/www.wientzek.ch\/index.php?rest_route=\/wp\/v2\/posts\/35","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wientzek.ch\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wientzek.ch\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wientzek.ch\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wientzek.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=35"}],"version-history":[{"count":1,"href":"https:\/\/www.wientzek.ch\/index.php?rest_route=\/wp\/v2\/posts\/35\/revisions"}],"predecessor-version":[{"id":36,"href":"https:\/\/www.wientzek.ch\/index.php?rest_route=\/wp\/v2\/posts\/35\/revisions\/36"}],"wp:attachment":[{"href":"https:\/\/www.wientzek.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=35"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wientzek.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=35"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wientzek.ch\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=35"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}