- 1 podmanコマンドとは?
- 2 検証環境
- 3 インストール方法
- 4 オプション一覧
- 5 イメージをダウンロード/削除する方法(pull/rmi)
- 6 コンテナの起動/停止/削除する方法(run/stop/rm)
- 7 コンテナでコマンドを実行する方法(exec)
- 8 Nginxコンテナを起動する方法
- 9 コンテナが出力するログを確認する方法(logs)
- Y 参考図書
- Z 参考情報
1 podmanコマンドとは?
Podmanは、RedHat社が開発したコンテナ管理ツールです。
RHEL 8では、Dockerコンテナエンジンとdockerコマンドが削除され、その代わりにpodmanコマンドが使用されます。Podmanは、Dockerと異なり、サービス(docker.service)の起動が不要です。
2 検証環境
サーバのAlmaLinux版数は以下のとおりです。
[root@server ~]# cat /etc/redhat-release AlmaLinux release 9.2 (Turquoise Kodkod)
カーネル版数は以下のとおりです。
[root@server ~]# uname -r 5.14.0-284.11.1.el9_2.x86_64
3 インストール方法
podmanパッケージをインストールします。
[root@server ~]# dnf -y install podman
podmanコマンドの版数を確認します。
[root@server ~]# podman -v podman version 4.9.4-rhel
4 オプション一覧
オプションは以下のとおりです。
[root@server ~]# podman --help Manage pods, containers and images Usage: podman [options] [command] Available Commands: attach Attach to a running container auto-update Auto update containers according to their auto-update policy build Build an image using instructions from Containerfiles commit Create new image based on the changed container compose Run compose workloads via an external provider such as docker-compose or podman-compose container Manage containers cp Copy files/folders between a container and the local filesystem create Create but do not start a container diff Display the changes to the object's file system events Show podman system events exec Run a process in a running container export Export container's filesystem contents as a tar archive farm Farm out builds to remote machines generate Generate structured data based on containers, pods or volumes healthcheck Manage health checks on containers help Help about any command history Show history of a specified image image Manage images images List images in local storage import Import a tarball to create a filesystem image info Display podman system information init Initialize one or more containers inspect Display the configuration of object denoted by ID kill Kill one or more running containers with a specific signal kube Play containers, pods or volumes from a structured file load Load image(s) from a tar archive login Log in to a container registry logout Log out of a container registry logs Fetch the logs of one or more containers machine Manage a virtual machine manifest Manipulate manifest lists and image indexes mount Mount a working container's root filesystem network Manage networks pause Pause all the processes in one or more containers pod Manage pods port List port mappings or a specific mapping for the container ps List containers pull Pull an image from a registry push Push an image to a specified destination rename Rename an existing container restart Restart one or more containers rm Remove one or more containers rmi Remove one or more images from local storage run Run a command in a new container save Save image(s) to an archive search Search registry for image secret Manage secrets start Start one or more containers stats Display a live stream of container resource usage statistics stop Stop one or more containers system Manage podman tag Add an additional name to a local image top Display the running processes of a container unmount Unmount working container's root filesystem unpause Unpause the processes in one or more containers unshare Run a command in a modified user namespace untag Remove a name from a local image update Update an existing container version Display the Podman version information volume Manage volumes wait Block on one or more containers Options: --cgroup-manager string Cgroup manager to use ("cgroupfs"|"systemd") (default "systemd") --conmon string Path of the conmon binary -c, --connection string Connection to use for remote Podman service --events-backend string Events backend to use ("file"|"journald"|"none") (default "journald") --help Help for podman --hooks-dir strings Set the OCI hooks directory path (may be set multiple times) (default [/usr/share/containers/oci/hooks.d]) --identity string path to SSH identity file, (CONTAINER_SSHKEY) --imagestore string Path to the 'image store', different from 'graph root', use this to split storing the image into a separate 'image store', see 'man containers-storage.conf' for details --log-level string Log messages above specified level (trace, debug, info, warn, warning, error, fatal, panic) (default "warn") --module strings Load the containers.conf(5) module --network-cmd-path string Path to the command for configuring the network --network-config-dir string Path of the configuration directory for networks --out string Send output (stdout) from podman to a file -r, --remote Access remote Podman service --root string Path to the graph root directory where images, containers, etc. are stored --runroot string Path to the 'run directory' where all state information is stored --runtime string Path to the OCI-compatible binary used to run containers. (default "crun") --runtime-flag stringArray add global flags for the container runtime --ssh string define the ssh mode (default "golang") --storage-driver string Select which storage driver is used to manage storage of images and containers --storage-opt stringArray Used to pass an option to the storage driver --syslog Output logging information to syslog as well as the console (default false) --tmpdir string Path to the tmp directory for libpod state content. Note: use the environment variable 'TMPDIR' to change the temporary storage location for container images, '/var/tmp'. (default "/run/libpod") --transient-store Enable transient container storage --url string URL to access Podman service (CONTAINER_HOST) (default "unix:///run/podman/podman.sock") -v, --version version for podman --volumepath string Path to the volume directory in which volume data is stored [root@server ~]#
5 イメージをダウンロード/削除する方法(pull/rmi)
5.1 AlmaLinuxのイメージダウンロード方法(最新版)
下記ページに記載されているタグを参考に、AlmaLinuxのイメージをダウンロードしてみます。
https://hub.docker.com/_/almalinux
タグにlatestを指定して、AlmaLinuxイメージの最新版をダウンロードしてみます。
[root@server ~]# podman pull almalinux:latest
イメージを確認します。ダウンロードしたイメージが最新版(latest)であることが確認できます。
[root@server ~]# podman images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/library/almalinux latest ce0e33343249 2 weeks ago 191 MB
イメージIDを指定して、イメージを削除します。
[root@server ~]# podman rmi ce0e33343249 Untagged: docker.io/library/almalinux:latest Deleted: ce0e333432494fd17367f2d5aa1e361fc16259a03151f3f1e0843c90f695dc1a
イメージを確認します。イメージが削除されたことがわかります。
[root@server ~]# podman images REPOSITORY TAG IMAGE ID CREATED SIZE
5.2 AlmaLinuxのイメージダウンロード方法(版数指定)
タグに9.4を指定して、AlmaLinuxイメージの9.4版をダウンロードしてみます。
[root@server ~]# podman pull almalinux:9.4 Resolved "almalinux" as an alias (/etc/containers/registries.conf.d/000-shortnames.conf) Trying to pull docker.io/library/almalinux:9.4... Getting image source signatures Copying blob 2d51c66a149e done | Copying config ce0e333432 done | Writing manifest to image destination ce0e333432494fd17367f2d5aa1e361fc16259a03151f3f1e0843c90f695dc1a
イメージを確認します。ダウンロードしたイメージが9.4版であることが確認できます。
[root@server ~]# podman images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/library/almalinux 9.4 ce0e33343249 2 weeks ago 191 MB
イメージIDを指定して、イメージを削除します。
[root@server ~]# podman rmi ce0e33343249 Untagged: docker.io/library/almalinux:9.4 Deleted: ce0e333432494fd17367f2d5aa1e361fc16259a03151f3f1e0843c90f695dc1a
イメージを確認します。イメージが削除されたことがわかります。
[root@server ~]# podman images REPOSITORY TAG IMAGE ID CREATED SIZE
5.3 openSUSEのイメージダウンロード方法(最新版)
DockerHubを確認すると、openSUSEイメージのタグの一覧が以下であることがわかります。
[root@server ~]# curl -s https://registry.hub.docker.com/v2/repositories/opensuse/leap/tags/ | jq '.results[].name' "latest" "15" "15.5" "15.6" "15.4" "15.3" "15.2" "15.1" "15.2.1" "15.0"
タグにlatestを指定して、openSUSEイメージの最新版をダウンロードしてみます。
[root@server ~]# podman pull docker.io/opensuse/leap:latest Trying to pull docker.io/opensuse/leap:latest... Getting image source signatures Copying blob cd2d8e5c43d1 done | Copying config f8872388ad done | Writing manifest to image destination f8872388adc38612a74bd8e234ecac71cfaf0c299dfc6c26ec86fc79dbcd879d
イメージを確認します。ダウンロードしたイメージが最新版であることが確認できます。
[root@server ~]# podman images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/opensuse/leap latest f8872388adc3 11 days ago 122 MB
イメージIDを指定して、イメージを削除します。
[root@server ~]# podman rmi f8872388adc3 Untagged: docker.io/opensuse/leap:latest Deleted: f8872388adc38612a74bd8e234ecac71cfaf0c299dfc6c26ec86fc79dbcd879d
イメージを確認します。openSUSEのイメージが削除されたことがわかります。
[root@server ~]# podman images REPOSITORY TAG IMAGE ID CREATED SIZE
5.4 openSUSEのイメージダウンロード方法(版数指定)
タグに15.5を指定して、openSUSEイメージの15.5版をダウンロードしてみます。
[root@server ~]# podman pull docker.io/opensuse/leap:15.5 Trying to pull docker.io/opensuse/leap:15.5... Getting image source signatures Copying blob cd2d8e5c43d1 done | Copying config f8872388ad done | Writing manifest to image destination f8872388adc38612a74bd8e234ecac71cfaf0c299dfc6c26ec86fc79dbcd879d
イメージを確認します。ダウンロードしたイメージが15.5版であることが確認できます。
[root@server ~]# podman images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/opensuse/leap 15.5 f8872388adc3 11 days ago 122 MB
イメージIDを指定してイメージを削除します。
[root@server ~]# podman rmi f8872388adc3 Untagged: docker.io/opensuse/leap:15.5 Deleted: f8872388adc38612a74bd8e234ecac71cfaf0c299dfc6c26ec86fc79dbcd879d
イメージを確認します。イメージが削除されたことがわかります。
[root@server ~]# podman images REPOSITORY TAG IMAGE ID CREATED SIZE
5.5 Ubuntuのイメージダウンロード方法(最新版)
下記ページに記載されているタグ一覧を参考に、Ubuntuの最新版イメージを取得してみます。
https://hub.docker.com/_/ubuntu
[root@server ~]# podman pull ubuntu:latest Resolved "ubuntu" as an alias (/etc/containers/registries.conf.d/000-shortnames.conf) Trying to pull docker.io/library/ubuntu:latest... Getting image source signatures Copying blob 49b384cc7b4a done | Copying config bf3dc08bfe done | Writing manifest to image destination bf3dc08bfed031182827888bb15977e316ad797ee2ccb63b4c7a57fdfe7eb31d
イメージを確認します。
[root@server ~]# podman images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/library/ubuntu latest bf3dc08bfed0 3 weeks ago 78.7 MB
確認したイメージIDを指定して、イメージを削除します。
[root@server ~]# podman rmi bf3dc08bfed0 Untagged: docker.io/library/ubuntu:latest Deleted: bf3dc08bfed031182827888bb15977e316ad797ee2ccb63b4c7a57fdfe7eb31d
イメージを確認します。イメージが削除されたことがわかります。
[root@server ~]# podman images REPOSITORY TAG IMAGE ID CREATED SIZE
5.6 Ubuntuのイメージダウンロード方法(版数指定)
タグに24.04を指定して、Ubuntuイメージの24.04版をダウンロードしてみます。
root@server ~]# podman pull ubuntu:24.04 Resolved "ubuntu" as an alias (/etc/containers/registries.conf.d/000-shortnames.conf) Trying to pull docker.io/library/ubuntu:24.04... Getting image source signatures Copying blob 49b384cc7b4a done | Copying config bf3dc08bfe done | Writing manifest to image destination bf3dc08bfed031182827888bb15977e316ad797ee2ccb63b4c7a57fdfe7eb31d
イメージを確認します。ダウンロードしたイメージが24.04版であることが確認できます。
[root@server ~]# podman images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/library/ubuntu 24.04 bf3dc08bfed0 3 weeks ago 78.7 MB
確認したイメージIDを指定して、イメージを削除します。
[root@server ~]# podman rmi 8264e2ec2ece
イメージを確認します。イメージが削除されたことがわかります。
[root@server ~]# podman images REPOSITORY TAG IMAGE ID CREATED SIZE
5.7 Nginxのイメージダウンロード方法(最新版)
下記ページに記載されているタグを参考に、Nginxのイメージを Docker Hubから取得してみます。
https://hub.docker.com/_/nginx
[root@server ~]# podman pull docker.io/library/nginx:latest Trying to pull docker.io/library/nginx:latest... Getting image source signatures Copying blob 45337c09cd57 done | Copying blob 933cc8470577 done | Copying blob a11fc495bafd done | Copying blob 971bb7f4fb12 done | Copying blob 09f376ebb190 done | Copying blob 999643392fb7 done | Copying blob de3b062c0af7 done | Copying config e784f45604 done | Writing manifest to image destination e784f4560448b14a66f55c26e1b4dad2c2877cc73d001b7cd0b18e24a700a070
イメージを確認します。
[root@server ~]# podman images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/library/nginx latest e784f4560448 3 weeks ago 192 MB
確認したイメージIDを指定して、イメージを削除します。
[root@server ~]# podman rmi e784f4560448 Untagged: docker.io/library/nginx:latest Deleted: e784f4560448b14a66f55c26e1b4dad2c2877cc73d001b7cd0b18e24a700a070
イメージを確認します。イメージが削除されたことがわかります。
[root@server ~]# podman images REPOSITORY TAG IMAGE ID CREATED SIZE
5.8 Nginxのイメージダウンロード方法(版数指定)
タグに1.25.5を指定して、Nginxイメージの1.25.5版をダウンロードしてみます。
[root@server ~]# podman pull docker.io/library/nginx:1.25.5 Trying to pull docker.io/library/nginx:1.25.5... Getting image source signatures Copying blob a11fc495bafd done | Copying blob 45337c09cd57 done | Copying blob 09f376ebb190 done | Copying blob 999643392fb7 done | Copying blob 933cc8470577 done | Copying blob 971bb7f4fb12 done | Copying blob de3b062c0af7 done | Copying config e784f45604 done | Writing manifest to image destination e784f4560448b14a66f55c26e1b4dad2c2877cc73d001b7cd0b18e24a700a070
イメージを確認します。
[root@server ~]# podman images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/library/nginx 1.25.5 e784f4560448 3 weeks ago 192 MB
イメージIDを指定して、イメージを削除します。
[root@server ~]# podman rmi e784f4560448 Untagged: docker.io/library/nginx:1.25.5 Deleted: e784f4560448b14a66f55c26e1b4dad2c2877cc73d001b7cd0b18e24a700a070
イメージを確認します。イメージが削除されたことがわかります。
[root@server ~]# podman images REPOSITORY TAG IMAGE ID CREATED SIZE
6 コンテナの起動/停止/削除する方法(run/stop/rm)
AlmaLinuxの最新版イメージを取得します。
[root@server ~]# podman pull almalinux:latest Resolved "almalinux" as an alias (/etc/containers/registries.conf.d/000-shortnames.conf) Trying to pull docker.io/library/almalinux:latest... Getting image source signatures Copying blob 2d51c66a149e done | Copying config ce0e333432 done | Writing manifest to image destination ce0e333432494fd17367f2d5aa1e361fc16259a03151f3f1e0843c90f695dc1a
取得したイメージを確認します。
[root@server ~]# podman images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/library/almalinux latest ce0e33343249 3 weeks ago 191 MB
IMAGE IDを指定して、testという名前のコンテナを起動します。
[root@server ~]# podman run -it --name test ce0e33343249 [root@31a5e80b3953 /]#
オプションの意味は以下のとおりです。
オプション | 意味 |
---|---|
--interactive(-i) | 対話式プロセスの場合には、-i と -t を併用してコンテナプロセスに端末を割り当てる |
--tty | コンテナ内でシェルを実行する際に使用する |
--name | コンテナの名前を指定する |
--detach(-d) | コンテナをバックグラウンドで実行する時に指定する |
ホストでもう1つターミナルを開いて、コンテナの状態を確認します。testという名前のコンテナが起動したことがわかります。
[root@server ~]# podman ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 31a5e80b3953 docker.io/library/almalinux:latest /bin/bash 24 seconds ago Up 24 seconds test
少し話がそれますが、コンテナを起動すると、ネームスペースが作成されることがわかります。なお、ip netnsコマンドの使い方は、ip netnsコマンドの使い方(ネットワークの実験の幅が広がるなぁ~) - hana_shinのLinux技術ブログを参照してください。
[root@server ~]# ip netns netns-793cbe84-d913-dfde-5e51-17154889d402 (id: 0)
コンテを停止します。
[root@server ~]# podman stop test test
コンテナの状態を確認します。
[root@server ~]# podman ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 31a5e80b3953 docker.io/library/almalinux:latest /bin/bash 3 minutes ago Exited (137) 13 seconds ago test
コンテナを停止すると、ネームスペースが削除されることがわかります。
[root@server ~]# ip netns [root@server ~]#
コンテナを削除します。
[root@server ~]# podman rm test test
コンテナの状態を確認します。コンテナが削除されたことがわかります。
[root@server ~]# podman ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7 コンテナでコマンドを実行する方法(exec)
7.1 bashを実行する方法
タグに15.5を指定して、OpenSUSEイメージの15.5版をダウンロードしてみます。
[root@server ~]# podman pull docker.io/opensuse/leap:15.5 Trying to pull docker.io/opensuse/leap:15.5... Getting image source signatures Copying blob fc28d7a394e1 done | Copying config 007974651d done | Writing manifest to image destination 007974651d34f8a848ad692926e51fbb9382615e9838e43ee060b6160bc52b4c
取得したイメージを確認します。
[root@server ~]# podman images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/opensuse/leap 15.5 007974651d34 6 days ago 122 MB
IMAGE IDを指定して、testという名前のコンテナを起動します。
[root@server ~]# podman run -it --name test 007974651d34 af0c63c76e00:/ #
コンテナ内でOpenSUSE版数を確認します。OpenSUSE版数は15.5であることがわかります。
af0c63c76e00:/ # cat /etc/os-release NAME="openSUSE Leap" VERSION="15.5" ID="opensuse-leap" ID_LIKE="suse opensuse" VERSION_ID="15.5" PRETTY_NAME="openSUSE Leap 15.5" ANSI_COLOR="0;32" CPE_NAME="cpe:/o:opensuse:leap:15.5" BUG_REPORT_URL="https://bugs.opensuse.org" HOME_URL="https://www.opensuse.org/" DOCUMENTATION_URL="https://en.opensuse.org/Portal:Leap" LOGO="distributor-logo-Leap"
testコンテナから抜けます。
af0c63c76e00:/ # exit exit [root@server ~]#
コンテナの状態を確認します。
[root@server ~]# podman ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES af0c63c76e00 docker.io/opensuse/leap:15.5 /bin/bash About a minute ago Exited (0) 17 seconds ago test
コンテナを削除します。
[root@server ~]# podman rm test test
コンテナの状態を確認します。コンテナが削除されたことがわかります。
[root@server ~]# podman ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7.2 catを実行する場合
AlmaLinuxの9.2版のイメージを取得します。
[root@server ~]# podman pull almalinux:9.2 Resolved "almalinux" as an alias (/etc/containers/registries.conf.d/000-shortnames.conf) Trying to pull docker.io/library/almalinux:9.2... Getting image source signatures Copying blob 92cbf8f63752 done | Copying config 1851aa77ac done | Writing manifest to image destination 1851aa77ac58181083ae0e68711dc38e434bec08ad53ef6f42c66cb1d100a6ef
取得したイメージを確認します。
[root@server ~]# podman images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/library/almalinux 9.2 1851aa77ac58 10 months ago 190 MB
IMAGE IDを指定して、testという名前のコンテナを起動します。
[root@server ~]# podman run -it -d --name test 1851aa77ac58 436f6e846043416113761d1d17b8fecf822a01a2840fa299fd7118732fdc1557
testコンテナで cat コマンドを実行します。
[root@server ~]# podman exec -it test cat /etc/redhat-release AlmaLinux release 9.2 (Turquoise Kodkod)
8 Nginxコンテナを起動する方法
タグにlatestを指定して、nginxイメージの最新版をダウンロードしてみます。
[root@server ~]# podman pull nginx:latest Resolved "nginx" as an alias (/var/cache/containers/short-name-aliases.conf) Trying to pull docker.io/library/nginx:latest... Getting image source signatures Copying blob 09f376ebb190 done | Copying blob 999643392fb7 done | Copying blob 971bb7f4fb12 done | Copying blob a11fc495bafd done | Copying blob 933cc8470577 done | Copying blob 45337c09cd57 done | Copying blob de3b062c0af7 done | Copying config e784f45604 done | Writing manifest to image destination e784f4560448b14a66f55c26e1b4dad2c2877cc73d001b7cd0b18e24a700a070
取得したイメージを確認します。
[root@server ~]# podman images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/library/nginx latest e784f4560448 3 weeks ago 192 MB
web1という名前でNginxコンテナを起動します。-pは、ホストの8080番ポートへのパケットをNginxがTCPパケットを待ち受けている80番ポートにDNATするオプションです。
[root@server ~]# podman run -d -p 8080:80 --name web1 e784f4560448 c8297889d408d1510ca62c22df1ddebd79db0324fd15eb7fb45f0b6785e57992
コンテナの状態を確認します。web1という名前のコンテナが動作していることがわかります。
[root@server ~]# podman ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c8297889d408 docker.io/library/nginx:latest nginx -g daemon o... 13 seconds ago Up 12 seconds 0.0.0.0:8080->80/tcp web1
web1コンテナで動作しているプロセスを確認します。nginx プロセスが動作していることがわかります。
[root@server ~]# podman top web1 USER PID PPID %CPU ELAPSED TTY TIME COMMAND root 1 0 0.000 25.456279266s ? 0s nginx: master process nginx -g daemon off; nginx 24 1 0.000 25.456595654s ? 0s nginx: worker process nginx 25 1 0.000 25.456702218s ? 0s nginx: worker process nginx 26 1 0.000 25.456799747s ? 0s nginx: worker process nginx 27 1 0.000 25.457019033s ? 0s nginx: worker process
コンテナとホストのポート番号の対応関係を確認します。コンテナの80番ポートがホストの8080番ポートに対応していることがわかります。
[root@server ~]# podman port web1 80/tcp -> 0.0.0.0:8080
iptablesのターゲットを確認します。Nginxコンテナを起動すると、以下のターゲットがiptablesに作成されます。
[root@server ~]# iptables -t nat -nvL |grep 8080 0 0 NETAVARK-HOSTPORT-SETMARK tcp -- * * 10.88.0.0/16 0.0.0.0/0 tcp dpt:8080 0 0 NETAVARK-HOSTPORT-SETMARK tcp -- * * 127.0.0.1 0.0.0.0/0 tcp dpt:8080 0 0 DNAT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:8080 to:10.88.0.6:80 0 0 NETAVARK-DN-1D8721804F16F tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:8080 /* dnat name: podman id: c8297889d408d1510ca62c22df1ddebd79db0324fd15eb7fb45f0b6785e57992 */ [root@server ~]#
iptablesの使い方の詳細は、以下を参照してください。
iptablesコマンドの使い方 - hana_shinのLinux技術ブログ
iptablesコマンドの使い方(ターゲットの使い方) - hana_shinのLinux技術ブログ
iptables-extensionsの使い方 - hana_shinのLinux技術ブログ
tcpdumpのフックポイント、Netfilterのチェイン、Qdiscのカーネル内の場所 - hana_shinのLinux技術ブログ
curlコマンドでNginxにアクセスしてみます。なお。curlコマンドの使い方は、curlコマンドの使い方 - hana_shinのLinux技術ブログを参照してください。
[root@server ~]# curl -I http://192.168.122.87:8080 HTTP/1.1 200 OK Server: nginx/1.25.5 Date: Tue, 28 May 2024 13:12:39 GMT Content-Type: text/html Content-Length: 615 Last-Modified: Tue, 16 Apr 2024 14:29:59 GMT Connection: keep-alive ETag: "661e8b67-267" Accept-Ranges: bytes
curlコマンドを1回実行すると、DNATターゲットが処理したパケット数が1増加していることがわかります。DNATでは、ホストが受信したTCPパケットの宛先IPアドレスを10.88.0.2、宛先ポート番号を8080から80に変更しています。
[root@server ~]# iptables -t nat -nvL |grep 8080 0 0 NETAVARK-HOSTPORT-SETMARK tcp -- * * 10.88.0.0/16 0.0.0.0/0 tcp dpt:8080 0 0 NETAVARK-HOSTPORT-SETMARK tcp -- * * 127.0.0.1 0.0.0.0/0 tcp dpt:8080 1 60 DNAT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:8080 to:10.88.0.6:80 1 60 NETAVARK-DN-1D8721804F16F tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:8080 /* dnat name: podman id: c8297889d408d1510ca62c22df1ddebd79db0324fd15eb7fb45f0b6785e57992 */
9 コンテナが出力するログを確認する方法(logs)
コンテナの状態を確認します。web1という名前のコンテナが動作しています。
[root@server ~]# podman ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c8297889d408 docker.io/library/nginx:latest nginx -g daemon o... About a minute ago Up About a minute 0.0.0.0:8080->80/tcp web1 [root@server ~]#
web1コンテナが出力するログを確認します。なお、-tオプションは、時刻を表示するオプションです。
[root@server ~]# podman logs -t web1 2024-05-28T22:11:21.257216000+09:00 /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration 2024-05-28T22:11:21.262837000+09:00 /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/ 2024-05-28T22:11:21.264553000+09:00 /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh -snip-
-fオプションは、ログ末尾からメッセージを表示するオプションです。
[root@server ~]# podman logs -ft web1 -snip- 2024-05-28T22:11:21.378042000+09:00 2024/05/28 13:11:21 [notice] 1#1: start worker process 26 2024-05-28T22:11:21.379112000+09:00 2024/05/28 13:11:21 [notice] 1#1: start worker process 27 2024-05-28T22:12:39.324924000+09:00 192.168.122.87 - - [28/May/2024:13:12:39 +0000] "HEAD / HTTP/1.1" 200 0 "-" "curl/7.76.1" "-"
Z 参考情報
私が業務や記事執筆で参考にした書籍を以下のページに記載します。
Linux技術のスキルアップをしよう! - hana_shinのLinux技術ブログ
コンテナーの構築、実行、および管理 Red Hat Enterprise Linux 8 | Red Hat Customer Portal