wiki/cli.podman.html
2022-07-29 15:41:17 +00:00

61 lines
21 KiB
HTML

<!DOCTYPE html><html><head><meta name="viewport" content="width=device-width"/><meta charSet="utf-8"/><title>Command line: Podman</title><script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script><script id="MathJax-script" async="" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script><script type="text/x-mathjax-config">
MathJax = {
tex: {
inlineMath: [ [&#x27;$&#x27;,&#x27;$&#x27;], [&#x27;\(&#x27;,&#x27;\)&#x27;] ],
displayMath: [ [&#x27;$$&#x27;,&#x27;$$&#x27;], [&#x27;[&#x27;,&#x27;]&#x27;] ]
},
options = {
processHtmlClass = &quot;math&quot;
}
}
</script><meta name="next-head-count" content="6"/><link rel="preload" href="/wiki/_next/static/css/52fc2ba29703df73922c.css" as="style"/><link rel="stylesheet" href="/wiki/_next/static/css/52fc2ba29703df73922c.css" data-n-g=""/><noscript data-n-css=""></noscript><link rel="preload" href="/wiki/_next/static/chunks/main-ae4733327bd95c4ac325.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/webpack-50bee04d1dc61f8adf5b.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/framework.9d524150d48315f49e80.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/commons.0e1c3f9aa780c2dfe9f0.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/pages/_app-8e3d0c58a60ec788aa69.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/940643274e605e7596ecea1f2ff8d83317a3fb76.4841a16762f602a59f00.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/pages/%5B%5B...slug%5D%5D-1aa198f87ede1cd0e1dc.js" as="script"/></head><body><div id="__next"><main><h1>Command line: Podman</h1><section class="post-metadata"><span>Date: <!-- -->2021-06-10 11:51:26 +08:00</span><span>Date modified: <!-- -->2021-07-20 23:31:29 +08:00</span></section><nav class="toc"><ol class="toc-level toc-level-1"><li class="toc-item toc-item-h1"><a href="/wiki/cli.podman#configuring-to-include-dockerio" class="toc-link toc-link-h1">Configuring to include docker.io</a></li><li class="toc-item toc-item-h1"><a href="/wiki/cli.podman#subcommands" class="toc-link toc-link-h1">Subcommands</a></li><li class="toc-item toc-item-h1"><a href="/wiki/cli.podman#examples" class="toc-link toc-link-h1">Examples</a><ol class="toc-level toc-level-2"><li class="toc-item toc-item-h2"><a href="/wiki/cli.podman#quickstart-for-pushing-a-container" class="toc-link toc-link-h2">Quickstart for pushing a container</a></li><li class="toc-item toc-item-h2"><a href="/wiki/cli.podman#interactive-selection-of-removing-images" class="toc-link toc-link-h2">Interactive selection of removing images</a></li><li class="toc-item toc-item-h2"><a href="/wiki/cli.podman#interactive-image-search-and-install" class="toc-link toc-link-h2">Interactive image search and install</a></li></ol></li></ol></nav><p>Podman is a daemonless container engine.
It was also designed to be a drop-in replacement for Docker with similar command-line interface and everything.
Thus, it is also compatible with Docker images and configurations (i.e., Dockerfiles).
</p><h1 id="configuring-to-include-dockerio">Configuring to include <code class="inline-verbatim">docker.io</code></h1><p>By default, Podman focuses on making the user concious about multiple registries outside DockerHub.
Thus, it doesn&#x27;t have any by default.
You have to configure it first.
For more information, see the <code class="inline-verbatim">podman.1</code> manual page and the linked pages.
</p><p>Here&#x27;s an incredibly simple example configuration that includes DockerHub.
</p><pre class="src-block"><code class="language-toml">unqualified-search-registries = [&#x27;docker.io&#x27;]
</code></pre><h1 id="subcommands">Subcommands</h1><p>Podman has Git-style command-line interface with subcommands and exclusive options.
</p><ul><li><p><code class="inline-verbatim">build</code> is for building images from the configuration — e.g., <code class="inline-code">podman build .</code> will build an image from the current directory with the Dockerfile.
</p><ul><li><p><code class="inline-verbatim">-t, --tag [NAME]</code> attaches a tag to the image.
</p></li><li><p><code class="inline-verbatim">-f, --file [FILE]</code> sets the name of the Dockerfile to be built from.
</p></li></ul></li><li><p><code class="inline-verbatim">run</code> will create a container from an image.
</p><ul><li><p><code class="inline-verbatim">-d, --detach</code> will make the process run in the background.
</p></li><li><p><code class="inline-verbatim">-it</code> will make an interactive shell.
</p></li><li><p><code class="inline-verbatim">-p, --publish</code> exposes the port of the image to the host.
</p></li></ul></li><li><p><code class="inline-verbatim">tag</code> will tag an existing image.
Useful for correcting tags for pushing into a remote registry.
</p></li><li><p><code class="inline-verbatim">image</code> is anything about interaction with images.
In fact, a lot of the subcommands presented so far are aliases with <code class="inline-verbatim">image</code> being the original — e.g., <code class="inline-verbatim">image tag</code> vs <code class="inline-verbatim">tag</code>, <code class="inline-verbatim">image pull</code> vs <code class="inline-verbatim">pull</code>, <code class="inline-verbatim">image rm</code> vs <code class="inline-verbatim">rmi</code>.
</p></li></ul><h1 id="examples">Examples</h1><p>Podman is a big tool so it needs a big list of examples.
</p><h2 id="quickstart-for-pushing-a-container">Quickstart for pushing a container</h2><p>As with big tools, comes with a big quickstart.
</p><pre class="src-block"><code class="language-shell"># Builds an image from the Dockerfile of the current directory.
podman build --tag todo-list-web-app .
# List the images to see if our app image has been built.
podman image list
# Assuming the app creates an HTTP server at port 5000, we&#x27;ll expose it to the host, making it accessible from there.
podman run -d -p 5111:5000 todo-list-web-app
# See if we did run a containerized version of our app.
podman container list
# Tag the image with the convention seen in Docker registry.
podman tag foodogsquared/python-helloworld:v1.0.0
# Push the image to the Docker registry (assuming you&#x27;ve already logged in to Docker registry).
podman push foodogsquared/python-helloworld
</code></pre><h2 id="interactive-selection-of-removing-images">Interactive selection of removing images</h2><p>What would be an example script without something like <a href="/wiki/cli.fzf">fzf</a>?
</p><pre class="src-block"><code class="language-bash">podman image list --format &quot;{{.ID}} {{.Repository}} {{.Tag}}&quot; \
| fzf --multi --prompt &quot;Choose images to remove &gt; &quot; \
| awk &#x27;{print $1}&#x27; \
| xargs podman image rm
</code></pre><h2 id="interactive-image-search-and-install">Interactive image search and install</h2><p>Yes, another one with fzf...
</p><pre class="src-block"><code class="language-bash">podman image search --format &quot;{{.Index}} {{.Name}}&quot; alpine \
| fzf --multi --prompt &quot;Choose images to install &gt; &quot; \
| awk &#x27;{print $2}&#x27; \
| xargs podman image pull
</code></pre></main></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"metadata":{"date":"\"2021-06-10 11:51:26 +08:00\"","date_modified":"\"2021-07-20 23:31:29 +08:00\"","language":"en","source":""},"title":"Command line: Podman","hast":{"type":"root","children":[{"type":"element","tagName":"nav","properties":{"className":"toc"},"children":[{"type":"element","tagName":"ol","properties":{"className":"toc-level toc-level-1"},"children":[{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h1","properties":{"id":"configuring-to-include-dockerio"},"children":[{"type":"text","value":"Configuring to include "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"docker.io"}]}]}]},"properties":{"className":"toc-item toc-item-h1"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h1","href":"/cli.podman#configuring-to-include-dockerio"},"children":[{"type":"text","value":"Configuring to include docker.io"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h1","properties":{"id":"subcommands"},"children":[{"type":"text","value":"Subcommands"}]}]},"properties":{"className":"toc-item toc-item-h1"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h1","href":"/cli.podman#subcommands"},"children":[{"type":"text","value":"Subcommands"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h1","properties":{"id":"examples"},"children":[{"type":"text","value":"Examples"}]}]},"properties":{"className":"toc-item toc-item-h1"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h1","href":"/cli.podman#examples"},"children":[{"type":"text","value":"Examples"}]},{"type":"element","tagName":"ol","properties":{"className":"toc-level toc-level-2"},"children":[{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h2","properties":{"id":"quickstart-for-pushing-a-container"},"children":[{"type":"text","value":"Quickstart for pushing a container"}]}]},"properties":{"className":"toc-item toc-item-h2"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h2","href":"/cli.podman#quickstart-for-pushing-a-container"},"children":[{"type":"text","value":"Quickstart for pushing a container"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h2","properties":{"id":"interactive-selection-of-removing-images"},"children":[{"type":"text","value":"Interactive selection of removing images"}]}]},"properties":{"className":"toc-item toc-item-h2"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h2","href":"/cli.podman#interactive-selection-of-removing-images"},"children":[{"type":"text","value":"Interactive selection of removing images"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h2","properties":{"id":"interactive-image-search-and-install"},"children":[{"type":"text","value":"Interactive image search and install"}]}]},"properties":{"className":"toc-item toc-item-h2"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h2","href":"/cli.podman#interactive-image-search-and-install"},"children":[{"type":"text","value":"Interactive image search and install"}]}]}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Podman is a daemonless container engine.\nIt was also designed to be a drop-in replacement for Docker with similar command-line interface and everything.\nThus, it is also compatible with Docker images and configurations (i.e., Dockerfiles).\n"}]},{"type":"element","tagName":"h1","properties":{"id":"configuring-to-include-dockerio"},"children":[{"type":"text","value":"Configuring to include "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"docker.io"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"By default, Podman focuses on making the user concious about multiple registries outside DockerHub.\nThus, it doesn't have any by default.\nYou have to configure it first.\nFor more information, see the "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"podman.1"}]},{"type":"text","value":" manual page and the linked pages.\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Here's an incredibly simple example configuration that includes DockerHub.\n"}]},{"type":"element","tagName":"pre","properties":{"className":["src-block"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-toml"]},"children":[{"type":"text","value":"unqualified-search-registries = ['docker.io']\n"}]}]},{"type":"element","tagName":"h1","properties":{"id":"subcommands"},"children":[{"type":"text","value":"Subcommands"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Podman has Git-style command-line interface with subcommands and exclusive options.\n"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"build"}]},{"type":"text","value":" is for building images from the configuration — e.g., "},{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"podman build ."}]},{"type":"text","value":" will build an image from the current directory with the Dockerfile.\n"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"-t, --tag [NAME]"}]},{"type":"text","value":" attaches a tag to the image.\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"-f, --file [FILE]"}]},{"type":"text","value":" sets the name of the Dockerfile to be built from.\n"}]}]}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"run"}]},{"type":"text","value":" will create a container from an image.\n"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"-d, --detach"}]},{"type":"text","value":" will make the process run in the background.\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"-it"}]},{"type":"text","value":" will make an interactive shell.\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"-p, --publish"}]},{"type":"text","value":" exposes the port of the image to the host.\n"}]}]}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"tag"}]},{"type":"text","value":" will tag an existing image.\n Useful for correcting tags for pushing into a remote registry.\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"image"}]},{"type":"text","value":" is anything about interaction with images.\n In fact, a lot of the subcommands presented so far are aliases with "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"image"}]},{"type":"text","value":" being the original — e.g., "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"image tag"}]},{"type":"text","value":" vs "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"tag"}]},{"type":"text","value":", "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"image pull"}]},{"type":"text","value":" vs "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"pull"}]},{"type":"text","value":", "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"image rm"}]},{"type":"text","value":" vs "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"rmi"}]},{"type":"text","value":".\n"}]}]}]},{"type":"element","tagName":"h1","properties":{"id":"examples"},"children":[{"type":"text","value":"Examples"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Podman is a big tool so it needs a big list of examples.\n"}]},{"type":"element","tagName":"h2","properties":{"id":"quickstart-for-pushing-a-container"},"children":[{"type":"text","value":"Quickstart for pushing a container"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"As with big tools, comes with a big quickstart.\n"}]},{"type":"element","tagName":"pre","properties":{"className":["src-block"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-shell"]},"children":[{"type":"text","value":"# Builds an image from the Dockerfile of the current directory.\npodman build --tag todo-list-web-app .\n\n# List the images to see if our app image has been built.\npodman image list\n\n# Assuming the app creates an HTTP server at port 5000, we'll expose it to the host, making it accessible from there.\npodman run -d -p 5111:5000 todo-list-web-app\n\n# See if we did run a containerized version of our app.\npodman container list\n\n# Tag the image with the convention seen in Docker registry.\npodman tag foodogsquared/python-helloworld:v1.0.0\n\n# Push the image to the Docker registry (assuming you've already logged in to Docker registry).\npodman push foodogsquared/python-helloworld\n"}]}]},{"type":"element","tagName":"h2","properties":{"id":"interactive-selection-of-removing-images"},"children":[{"type":"text","value":"Interactive selection of removing images"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"What would be an example script without something like "},{"type":"element","tagName":"a","properties":{"href":"/cli.fzf"},"children":[{"type":"text","value":"fzf"}]},{"type":"text","value":"?\n"}]},{"type":"element","tagName":"pre","properties":{"className":["src-block"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-bash"]},"children":[{"type":"text","value":"podman image list --format \"{{.ID}} {{.Repository}} {{.Tag}}\" \\\n | fzf --multi --prompt \"Choose images to remove \u003e \" \\\n | awk '{print $1}' \\\n | xargs podman image rm\n"}]}]},{"type":"element","tagName":"h2","properties":{"id":"interactive-image-search-and-install"},"children":[{"type":"text","value":"Interactive image search and install"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Yes, another one with fzf...\n"}]},{"type":"element","tagName":"pre","properties":{"className":["src-block"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-bash"]},"children":[{"type":"text","value":"podman image search --format \"{{.Index}} {{.Name}}\" alpine \\\n | fzf --multi --prompt \"Choose images to install \u003e \" \\\n | awk '{print $2}' \\\n | xargs podman image pull\n"}]}]}]},"backlinks":[]},"__N_SSG":true},"page":"/[[...slug]]","query":{"slug":["cli.podman"]},"buildId":"Ie9t5zutrXP6Of75Cb5xF","assetPrefix":"/wiki","nextExport":false,"isFallback":false,"gsp":true}</script><script nomodule="" src="/wiki/_next/static/chunks/polyfills-99d808df29361cf7ffb1.js"></script><script src="/wiki/_next/static/chunks/main-ae4733327bd95c4ac325.js" async=""></script><script src="/wiki/_next/static/chunks/webpack-50bee04d1dc61f8adf5b.js" async=""></script><script src="/wiki/_next/static/chunks/framework.9d524150d48315f49e80.js" async=""></script><script src="/wiki/_next/static/chunks/commons.0e1c3f9aa780c2dfe9f0.js" async=""></script><script src="/wiki/_next/static/chunks/pages/_app-8e3d0c58a60ec788aa69.js" async=""></script><script src="/wiki/_next/static/chunks/940643274e605e7596ecea1f2ff8d83317a3fb76.4841a16762f602a59f00.js" async=""></script><script src="/wiki/_next/static/chunks/pages/%5B%5B...slug%5D%5D-1aa198f87ede1cd0e1dc.js" async=""></script><script src="/wiki/_next/static/Ie9t5zutrXP6Of75Cb5xF/_buildManifest.js" async=""></script><script src="/wiki/_next/static/Ie9t5zutrXP6Of75Cb5xF/_ssgManifest.js" async=""></script></body></html>