mirror of
https://github.com/foo-dogsquared/wiki.git
synced 2025-02-07 09:18:59 +00:00
61 lines
21 KiB
HTML
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: [ ['$','$'], ['\(','\)'] ],
|
||
|
displayMath: [ ['$$','$$'], ['[',']'] ]
|
||
|
},
|
||
|
options = {
|
||
|
processHtmlClass = "math"
|
||
|
}
|
||
|
}
|
||
|
</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'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's an incredibly simple example configuration that includes DockerHub.
|
||
|
</p><pre class="src-block"><code class="language-toml">unqualified-search-registries = ['docker.io']
|
||
|
</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'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'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 "{{.ID}} {{.Repository}} {{.Tag}}" \
|
||
|
| fzf --multi --prompt "Choose images to remove > " \
|
||
|
| awk '{print $1}' \
|
||
|
| 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 "{{.Index}} {{.Name}}" alpine \
|
||
|
| fzf --multi --prompt "Choose images to install > " \
|
||
|
| awk '{print $2}' \
|
||
|
| 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","v
|