{"id":2684,"date":"2024-02-13T18:52:33","date_gmt":"2024-02-13T18:52:33","guid":{"rendered":"https:\/\/blog.samarthya.me\/wps\/?p=2684"},"modified":"2024-02-14T18:16:00","modified_gmt":"2024-02-14T18:16:00","slug":"non-root-podman-and-molecule","status":"publish","type":"post","link":"https:\/\/blog.samarthya.me\/wps\/2024\/02\/13\/non-root-podman-and-molecule\/","title":{"rendered":"Non root `podman` and `molecule`"},"content":{"rendered":"<div class=\"wp-block-image\">\n<figure class=\"alignleft size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"512\" height=\"512\" src=\"https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2024\/02\/molecule.png\" alt=\"\" class=\"wp-image-2685\" srcset=\"https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2024\/02\/molecule.png 512w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2024\/02\/molecule-150x150@2x.png 300w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2024\/02\/molecule-150x150.png 150w\" sizes=\"(max-width: 512px) 100vw, 512px\" \/><\/figure>\n<\/div>\n\n\n<p class=\"has-medium-font-size\">On my <code>Centos8<\/code> I was facing issue when I was trying to run Molecule on a centos machine which is running <code>podman<\/code> as a non root user. Also, I am using the driver &#8211; <code>docker<\/code> and not <code>podman<\/code>, so to overcome the aliases and references issues I have installed <code>podman-docker<\/code>. <\/p>\n\n\n\n<h2 class=\"wp-block-heading has-medium-font-size\" style=\"text-transform:uppercase\"><a href=\"https:\/\/en.wikipedia.org\/wiki\/Docker_(software)\"><\/a> What is Podman?<\/h2>\n\n\n\n<p class=\"has-medium-font-size\">Podman is a powerful tool for managing containers and pods, but it doesn&#8217;t have the exact same command-line interface (CLI) as Docker. This can be a hurdle for users accustomed to Docker workflows. <\/p>\n\n\n\n<p class=\"has-medium-font-size\">That&#8217;s where <strong>podman-docker<\/strong> comes in. This package installs a script named docker that emulates the <code>Docker&nbsp;CLI<\/code>. <a href=\"https:\/\/en.wikipedia.org\/wiki\/Command-line_interface\"><\/a>It also creates links between all <code>Docker CLI<\/code>&nbsp;and <code>podman<\/code>.<\/p>\n\n\n\n<p><strong>Podman-docker<\/strong> is a <strong>compatibility layer<\/strong> that allows you to use familiar Docker commands directly with Podman. It translates Docker commands into Podman commands under the hood, essentially <strong>bridging the gap between the two tools<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Error<\/h2>\n\n\n\n<p>With the compatibility layer <code>podman-docker<\/code>; I was facing multiple issues.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Exception &#8211; 1<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">docker.errors.DockerException: Error while fetching server API version: ('Connection aborted.', PermissionError(13, 'Permission denied'))<\/pre>\n\n\n\n<p>What I could gather looking at this error was that  it is trying to reach out to docker service but since I have podman something in place. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><code>podman.socket<\/code><\/h2>\n\n\n\n<p>Podman.socket is a Unix socket file that allows communication with the Podman API. It functions in two main ways:<\/p>\n\n\n\n<p><strong>1. Socket Activation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>In combination with <code>systemd<\/code>,&nbsp;Podman.socket can enable&nbsp;<strong>on-demand service activation<\/strong>.&nbsp;As soon as a client connects to the socket,&nbsp;systemd starts the Podman API service,&nbsp;eliminating unnecessary background processes.&nbsp;This optimizes resource usage and improves security.<\/li>\n<\/ul>\n\n\n\n<p><strong>2. Docker Compatibility:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Podman.socket can be used to emulate the Docker API,&nbsp;allowing tools and scripts designed for Docker to work with Podman.&nbsp;This is achieved by translating Docker commands into Podman commands before execution.&nbsp;This compatibility layer is particularly useful for:\n<ul class=\"wp-block-list\">\n<li><strong>Transitioning from Docker:<\/strong>&nbsp;Users familiar with Docker can continue using existing workflows without significant changes.<\/li>\n\n\n\n<li><strong>Team Collaboration:<\/strong>&nbsp;Teams using Docker tools can continue working together even if individual members use Podman.<\/li>\n\n\n\n<li><strong>Supporting existing scripts:<\/strong>&nbsp;Scripts written for Docker can be used with Podman without modifications.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p>Enabling the <code>podman.socket<\/code> for the current user<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color has-small-font-size wp-elements-97a3805e6e32412677447fd53d05fbb1\"><code>systemctl enable --now --user podman.socket<\/code><\/pre>\n\n\n\n<p>Check the status<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color has-small-font-size wp-elements-2c19d8173a2006e163b97b53aa6b045f\"><code>systemctl status --user podman.socket\n\u25cf podman.socket - Podman API Socket\n   Loaded: loaded (\/usr\/lib\/systemd\/user\/podman.socket; enabled; vendor preset: enabled)\n   Active: active (listening) since Tue 2024-02-13 18:44:17 UTC; 8s ago\n     Docs: man:podman-system-service(1)\n   Listen: \/run\/user\/0000\/podman\/podman.sock (Stream)\n   CGroup: \/user.slice\/user-0000.slice\/user@0000.service\/podman.socket<\/code><\/pre>\n\n\n\n<p>Once it was running it was still giving the same error<\/p>\n\n\n\n<p>exporting <code>DOCKER_HOST<\/code><\/p>\n\n\n\n<p>We use <code class=\"\">export DOCKER_HOST<\/code> to tell the Docker client where to find the Docker daemon it needs to communicate with. It&#8217;s particularly useful in specific scenarios, but it&#8217;s essential to understand its function and potential drawbacks.<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color has-small-font-size wp-elements-97825300b48684b7f4dad73b54522ffe\"><code>export DOCKER_HOST=unix:\/\/\/run\/user\/0000\/podman\/podman.sock<\/code><\/pre>\n\n\n\n<p>Once this property was set molecule was able to communicate with the <code>docker<\/code>\/<code>podman<\/code> and without errors.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Error &#8211; 2<\/h3>\n\n\n\n<p>The next error I got when I executed my molecule test is as under<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color has-small-font-size wp-elements-714ca1f1f09b8b19926078cc6e79147b\"><code>UNREACHABLE! => {\n    \"changed\": false,\n    \"msg\": \"Failed to create temporary directory. In some cases, you may have been able to authenticate and did not have permissions on the target directory. Consider changing the remote tmp path in ansible.cfg to a path rooted in \\\"\/tmp\\\", for more error information use -vvv. Failed command was: ( umask 77 &amp;&amp; mkdir -p \\\"` echo ~\/.ansible\/tmp `\\\"&amp;&amp; mkdir \\\"` echo ~\/.ansible\/tmp\/ansible-tmp-1707932756.4075935-520325-234920630732299 `\\\" &amp;&amp; echo ansible-tmp-1707932756.4075935-520325-234920630732299=\\\"` echo ~\/.ansible\/tmp\/ansible-tmp-1707932756.4075935-520325-234920630732299 `\\\" ), exited with result 125\",\n    \"unreachable\": true\n}<\/code><\/pre>\n\n\n\n<p>To resolve this you need to set the <code>PODMAN_SOCK<\/code> variable.<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color has-small-font-size wp-elements-819ef2336e98fd4fce582336b4c14644\"><code>export PODMAN_SOCK=\/run\/user\/0000\/podman\/podman.sock<\/code><\/pre>\n\n\n\n<p>Once set I ran the <code>molecule test<\/code> again and voila! all was green.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Versions<\/h3>\n\n\n\n<p>I have the following  version of molecule and I am using <code>podman<\/code><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><code>molecule --version<\/code><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>molecule 6.0.3 using python 3.12 \n    ansible:2.16.3\n    azure:23.5.0 from molecule_plugins\n    containers:23.5.0 from molecule_plugins requiring collections: ansible.posix&gt;=1.3.0 community.docker&gt;=1.9.1 containers.podman&gt;=1.8.1\n    default:6.0.3 from molecule\n    docker:23.5.0 from molecule_plugins requiring collections: community.docker&gt;=3.0.2 ansible.posix&gt;=1.4.0\n    ec2:23.5.0 from molecule_plugins\n    gce:23.5.0 from molecule_plugins requiring collections: google.cloud&gt;=1.0.2 community.crypto&gt;=1.8.0\n    podman:23.5.0 from molecule_plugins requiring collections: containers.podman&gt;=1.7.0 ansible.posix&gt;=1.3.0\n    vagrant:23.5.0 from molecule_plugins<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><code>ansible --version<\/code><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>ansible &#91;core 2.16.3]<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><code>podman --version<\/code><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>podman version 4.8.3\n\n&gt; rpm -qa \"podman-docker\"\npodman-docker-4.8.3-1.module_el8+804+f131391c.noarch\n\n\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>On my Centos8 I was facing issue when I was trying to run Molecule on a centos machine which is running podman as a non root user. Also, I am using the driver &#8211; docker and not podman, so to overcome the aliases and references issues I have installed podman-docker. What is Podman? Podman is [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":2686,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[299,34],"tags":[283],"class_list":["post-2684","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ansible","category-technical","tag-molecule"],"_links":{"self":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts\/2684","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/comments?post=2684"}],"version-history":[{"count":5,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts\/2684\/revisions"}],"predecessor-version":[{"id":2692,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts\/2684\/revisions\/2692"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/media\/2686"}],"wp:attachment":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/media?parent=2684"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/categories?post=2684"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/tags?post=2684"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}