{"id":524,"date":"2022-03-15T23:40:36","date_gmt":"2022-03-15T15:40:36","guid":{"rendered":"https:\/\/codestrian.com\/?p=524"},"modified":"2023-03-01T00:00:24","modified_gmt":"2023-02-28T16:00:24","slug":"setting-up-rootless-docker-on-debian","status":"publish","type":"post","link":"https:\/\/codestrian.com\/index.php\/2022\/03\/15\/setting-up-rootless-docker-on-debian\/","title":{"rendered":"Setting up Rootless Docker on Debian"},"content":{"rendered":"<h1>Introduction<\/h1>\n<p>Docker has become one of the most popular tool in the recent years. This is because it allows developer to deploy their application to any machine with the same setup. Think of it like running a Java program on any machine with JVM installed. Due to the popularity, it is also important for us to secure the docker containers. One of the features that was released by the Docker team was the rootless mode which disables the root access from docker container.<\/p>\n<p>In this tutorial, I will be going through how to setup docker rootless mode in the proper way on Debian.<\/p>\n<p>Let's create a docker user before we start<\/p>\n<pre><code>sudo useradd -m -s \/bin\/bash docker\nsudo passwd docker\nsudo usermod -aG sudo docker<\/code><\/pre>\n<p>and lets login as newly created user <strong><em>docker<\/em><\/strong>.<\/p>\n<h1>Install Rootless Docker<\/h1>\n<h2>Set up repository<\/h2>\n<pre><code>sudo apt-get update &amp;&amp; \\\nsudo apt-get install -y ca-certificates curl gnupg lsb-release uidmap iptables dbus-user-session fuse-overlayfs &amp;&amp; \\\ncurl -fsSL https:\/\/download.docker.com\/linux\/debian\/gpg | sudo gpg --dearmor -o  \/usr\/share\/keyrings\/docker-archive-keyring.gpg &amp;&amp; \\\necho &quot;deb [arch=$(dpkg --print-architecture) signed-by=\/usr\/share\/keyrings\/docker-archive-keyring.gpg] https:\/\/download.docker.com\/linux\/debian $(lsb_release -cs) stable&quot; | sudo tee \/etc\/apt\/sources.list.d\/docker.list &gt; \/dev\/null<\/code><\/pre>\n<p>Relogin after running the above command.<\/p>\n<h2>Install Docker Engine<\/h2>\n<pre><code>sudo apt update &amp;&amp; \\\nsudo apt-get install -y docker-ce docker-ce-cli containerd.io<\/code><\/pre>\n<p>Since we are running rootless docker, we will proceed to disable the rootful docker<\/p>\n<pre><code>sudo systemctl disable --now docker.service docker.socket<\/code><\/pre>\n<p>Reboot the system after disabling<\/p>\n<h2>Install the setup script<\/h2>\n<pre><code>sudo apt-get update\nsudo apt-get install -y docker-ce-rootless-extras <\/code><\/pre>\n<h2>Install Rootless Docker<\/h2>\n<p>run the following as non-root to install rootless docker.<\/p>\n<pre><code>dockerd-rootless-setuptool.sh install<\/code><\/pre>\n<p>next enable rootless docker to launch on startup.<\/p>\n<pre><code>systemctl --user enable docker\nsudo loginctl enable-linger $(whoami)<\/code><\/pre>\n<p>Congratulations, you have now successfully setup rootless docker. I will share with you on how to expose docker API so that it can be managed by tools like portainer or used by jenkins.<\/p>\n<p>If you are doing this on ubuntu, you will need to enable cgroup v2 to avoid permission issues in some containers. please refer to <a href=\"https:\/\/rootlesscontaine.rs\/getting-started\/common\/cgroup2\/\">https:\/\/rootlesscontaine.rs\/getting-started\/common\/cgroup2\/<\/a><\/p>\n<p>Relevant links:<br \/>\n<a href=\"https:\/\/docs.docker.com\/engine\/security\/rootless\/\">https:\/\/docs.docker.com\/engine\/security\/rootless\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Docker has become one of the most popular tool in the recent years. This is because it allows developer to deploy their application to any machine with the same setup. Think of it like running a Java program on any machine with JVM installed. Due to the popularity, it [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[62,42],"tags":[],"_links":{"self":[{"href":"https:\/\/codestrian.com\/index.php\/wp-json\/wp\/v2\/posts\/524"}],"collection":[{"href":"https:\/\/codestrian.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codestrian.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codestrian.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codestrian.com\/index.php\/wp-json\/wp\/v2\/comments?post=524"}],"version-history":[{"count":11,"href":"https:\/\/codestrian.com\/index.php\/wp-json\/wp\/v2\/posts\/524\/revisions"}],"predecessor-version":[{"id":591,"href":"https:\/\/codestrian.com\/index.php\/wp-json\/wp\/v2\/posts\/524\/revisions\/591"}],"wp:attachment":[{"href":"https:\/\/codestrian.com\/index.php\/wp-json\/wp\/v2\/media?parent=524"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codestrian.com\/index.php\/wp-json\/wp\/v2\/categories?post=524"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codestrian.com\/index.php\/wp-json\/wp\/v2\/tags?post=524"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}