日記

mac OSでもpodmanが利用できるらしかったのでインストールして見た。
mac OS上でLinuxコンテナの実行環境を動かして、その上でLinuxコンテナを実行する、というアプローチである。

podmanはルートレスで実行できるコンテナ実行環境だ。
podman run のようにしてコンテナ実行できる。
dockerコマンドをそのまま置き換えることが可能である。

Linuxコンテナ実行環境の作成

VirtualBox上の仮想マシンでLinux Containersを実行できる環境を作成する。
boot2podmanという実行環境があるらしいので、そちらを使用する。

$ curl -L https://github.com/boot2podman/machine/releases/download/v0.17/podman-machine.darwin-amd64 --output /usr/local/bin/podman-machine
$ chmod +x /usr/local/bin/podman-machine

以下のコマンドを実行すると、isoイメージがダウンロードされ仮想マシンが起動する。
isoイメージファイルを変更したい場合は、オプション--virtualbox-boot2podman-urlで指定可能である。

$ podman-machine create \
  --virtualbox-boot2podman-url https://github.com/boot2podman/boot2podman/releases/download/v0.26/boot2podman.iso \
  --virtualbox-memory="4096" \
  --virtualbox-share-folder .:/shared \
  podman-box
Running pre-create checks...
(podman-box) Boot2Podman URL was explicitly set to "https://github.com/boot2podman/boot2podman/releases/download/v0.26/boot2podman.iso" at create time, so Podman Machine cannot upgrade this machine to the latest version.
Creating machine...
(podman-box) Boot2Podman URL was explicitly set to "https://github.com/boot2podman/boot2podman/releases/download/v0.26/boot2podman.iso" at create time, so Podman Machine cannot upgrade this machine to the latest version.
(podman-box) Downloading /Users/guest/.local/machine/cache/boot2podman.iso from https://github.com/boot2podman/boot2podman/releases/download/v0.26/boot2podman.iso...
(podman-box) 0%....10%....20%....30%....40%....50%....60%....70%....80%....90%....100%
(podman-box) Creating VirtualBox VM...
(podman-box) Creating SSH key...
(podman-box) Starting the VM...
(podman-box) Check network to re-create if needed...
(podman-box) Waiting for an IP...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with boot2podman...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Checking connection to Podman...
Podman is up and running!
To see how to connect your Podman client to Podman server running on this virtual machine, run: podman-machine env podman-box

無事に仮想マシンを起動できているようだ、envコマンドで動作環境を確認する。

$ podman-machine ls
NAME         ACTIVE   DRIVER       STATE     URL                    ERRORS
podman-box   -        virtualbox   Running   tcp://192.168.99.101  
$ podman-machine env podman-box
export PODMAN_USER="root"
export PODMAN_HOST="127.0.0.1"
export PODMAN_PORT="64007"
export PODMAN_IDENTITY_FILE="/Users/guest/.local/machine/machines/podman-box/id_rsa"
export PODMAN_IGNORE_HOSTS="true"
export PODMAN_MACHINE_NAME="podman-box"
# Run this command to configure your shell: 
# eval $(podman-machine env podman-box)

コンテナの実行

仮想環境にログインし、nginxコンテナを動かしてみる。

$ podman-machine ssh podman-box
        .---.        b o o t 2                 mm             https://podman.io
       /o   o\                                 ##                              
    __(=  "  =)__    ##m###m    m####m    m###m##  ####m##m   m#####m  ##m####m
     //\'-=-'/\\     ##"  "##  ##"  "##  ##"  "##  ## ## ##   " mmm##  ##"   ##
        )   (        ##    ##  ##    ##  ##    ##  ## ## ##  m##"""##  ##    ##
       /     \       ###mm##"  "##mm##"  "##mm###  ## ## ##  ##mmm###  ##    ##
  ____/  / \  \____  ## """      """"      """ ""  "" "" ""   """" ""  ""    ""
 `------'`"`'------' ##                                                art: jgs
tc@podman-box:~$ podman ps
CONTAINER ID  IMAGE  COMMAND  CREATED  STATUS  PORTS  NAMES
tc@podman-box:~$ podman pull nginx:1.18
Trying to pull docker.io/library/nginx:1.18...
Getting image source signatures
Copying blob 144135394326 done  
Copying blob 54fec2fa59d0 done  
Copying blob 9c9c769e5838 done  
Copying blob 90b7f1c33d6d done  
Copying config 1857c2b713 [======================================] 6.8KiB / 6.8KiB
Writing manifest to image destination
Storing signatures
1857c2b71337791d5f98787ab54782f528e2c63f78c4df125a2572a7ee4e3a67
tc@podman-box:~$ podman run -p 8080:80 -d --rm --name nginx-container nginx:1.18
469e347a6b648dda4d347d97a293c421f61b91152ac50dafb84502c4ea9ce14b
tc@podman-box:~$ podman ps
CONTAINER ID  IMAGE                         COMMAND               CREATED        STATUS            PORTS                 NAMES
469e347a6b64  docker.io/library/nginx:1.18  nginx -g daemon o...  3 seconds ago  Up 2 seconds ago  0.0.0.0:8080->80/tcp  nginx-container
tc@podman-box:~$ wget -q -O- http://127.0.0.1:8080/
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

おぉ、無事にコンテナ実行できているようだ。
VirtualBoxでポートフォワードを設定してやると、ホストマシンからpodmanのbox上のnginxにアクセスできた。

参考リンク


トップ   一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
目次
ダブルクリックで閉じるTOP | 閉じる
GO TO TOP