{"id":1571,"date":"2017-02-24T22:29:59","date_gmt":"2017-02-25T02:29:59","guid":{"rendered":"https:\/\/lowtek.ca\/roo\/?p=1571"},"modified":"2017-02-24T22:29:59","modified_gmt":"2017-02-25T02:29:59","slug":"server-upgrade-part-4-systemd-and-docker-containers","status":"publish","type":"post","link":"https:\/\/lowtek.ca\/roo\/2017\/server-upgrade-part-4-systemd-and-docker-containers\/","title":{"rendered":"Server Upgrade Part 4: systemd and docker containers"},"content":{"rendered":"<p>I&#8217;ve set the BIOS on the new server to resume running after a power failure. The OS happily comes back no problem, and docker even\u00a0starts up &#8211; but none of the containers.<\/p>\n<p>Apparently in <a href=\"https:\/\/docs.docker.com\/engine\/admin\/host_integration\/\">docker 1.2 there is now support to restart your containers after boot<\/a>, this sounds useful, but\u00a0the version of docker in Ubuntu 16.04 is\u00a01.12.1, close but not quite recent enough.<\/p>\n<p>No worries, we can use systemd to sort this out. The docker documentation has some examples, but <a href=\"http:\/\/container-solutions.com\/running-docker-containers-with-systemd\/\">I found an article<\/a> which takes a slightly different approach &#8211; one they claim is more aligned to CoreOS.<\/p>\n<p>Adding our own services to systemd is simply a matter of adding a file to \/etc\/systemd\/system\/. The very first one I want to add is one to host my own registry. Now you probably don&#8217;t want to host your own <a href=\"https:\/\/docs.docker.com\/registry\/\">registry<\/a> since you could simply use the public <a href=\"https:\/\/hub.docker.com\/\">dockerhub<\/a>, or any number of other solutions. However, I&#8217;m also the type of person who hosts their own email, so of course I&#8217;m going to host my own registry.<\/p>\n<pre class=\"lang:default decode:true\">[Unit]\r\nDescription=Private Docker Registry\r\nAfter=docker.service\r\nRequires=docker.service\r\n\r\n[Service]\r\nTimeoutStartSec=0\r\nRestart=always\r\nExecStartPre=-\/usr\/bin\/docker stop %n\r\nExecStartPre=-\/usr\/bin\/docker rm %n\r\nExecStartPre=\/usr\/bin\/docker pull registry\r\nExecStart=\/usr\/bin\/docker run -p 5000:5000 -v \/var\/lib\/registry:\/var\/lib\/registry --name %n registry\r\n\r\n[Install]\r\nWantedBy=multi-user.target<\/pre>\n<p>The %n in the file is replaced with the &#8216;full unit name&#8217;. If we save this file as \/etc\/systemd\/system\/docker-registry.service the unit name should be docker-registry.<\/p>\n<p>In a\u00a0simple configuration, the local docker registry will persist data as a docker volume.\u00a0I decided it was safer to map to a local file tree.<\/p>\n<p>Once you&#8217;ve created the file \/etc\/systemd\/system\/docker-registry.service we need to reload the systemd daemon and start the service.<\/p>\n<pre class=\"lang:default decode:true\">$ sudo systemctl daemon-reload\r\n$ sudo systemctl start docker-registry.service<\/pre>\n<p>If all\u00a0has gone well, <code>docker ps<\/code> should show us the new running registry (it does). Now let&#8217;s make it start every boot.<\/p>\n<pre class=\"lang:default decode:true\">$ sudo systemctl enable docker-registry.service<\/pre>\n<p>And yup, a reboot and we see the registry has started. So now we have a local registry to store our containers in, and a pattern to apply to make them services that start even after a reboot (expected or unexpected).<\/p>\n<p>Pushing images to a local registry is covered in the <a href=\"https:\/\/docs.docker.com\/registry\/deploying\/#\/running-on-localhost\">documentation<\/a>. I might later want to <a href=\"https:\/\/docs.docker.com\/registry\/deploying\/#\/running-a-domain-registry\">add a certificate<\/a> to the registry, but it is not required.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve set the BIOS on the new server to resume running after a power failure. The OS happily comes back no problem, and docker even\u00a0starts up &#8211; but none of the containers. Apparently in docker 1.2 there is now support to restart your containers after boot, this sounds useful, but\u00a0the version of docker in Ubuntu &hellip; <a href=\"https:\/\/lowtek.ca\/roo\/2017\/server-upgrade-part-4-systemd-and-docker-containers\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Server Upgrade Part 4: systemd and docker containers&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-1571","post","type-post","status-publish","format-standard","hentry","category-computing"],"_links":{"self":[{"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/posts\/1571","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/comments?post=1571"}],"version-history":[{"count":3,"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/posts\/1571\/revisions"}],"predecessor-version":[{"id":1574,"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/posts\/1571\/revisions\/1574"}],"wp:attachment":[{"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/media?parent=1571"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/categories?post=1571"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/tags?post=1571"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}