0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Podmanことはじめ

Last updated at Posted at 2025-09-23

Podman

Podman: Rootlessで使えるdocker様コンテナ。

関連ポスト: Apptainerことはじめ #初心者 - Qiita, Docker備忘録 #初心者 - Qiita

Ubuntu 22.04へのインストール

sudo apt install podman

でインストール終了。
podman -vpodman version 3.4.4が、podman info --debug |grep rootless rootless: trueが得られれば、概ね確認完了。

例えば

podman pull docker.io/library/alpine:latest
podman run --rm -it alpine sh

でalpineにshellで入れれば、設定完了が確認できる。

トラブルシューティング Error: open /etc/containers/policy.json: no such file or directory

podman pull docker.io/library/alpine:latest

の実行で以下のエラーが出た。

Error: open /etc/containers/policy.json: no such file or directory

確認すると以下のファイルが存在している:

/etc/containers/policy.json.dpkg-new
{
  "default": [
    {
      "type": "insecureAcceptAnything"
    }
  ]
}

この状況をchatgptに尋ねる(2025.09.23時点)と、どうも

パッケージのインストールやアップデートの途中で設定ファイルがまだ適用されていない状態で止まっている可能性が高いです。

とのことだった。(確かに最初のインストール時はsudo apt install podman-*でインストールして、いくつかこけていた。)
一旦消して再度入れれば良いだろうということで、

sudo apt remove podman
sudo apt purege podman
sudo apt instal podman

で、インストールしたところ、無事

/etc/containers/policy.json
{
    "default": [
        {
            "type": "insecureAcceptAnything"
        }
    ]
}

た生成されていた。

Build できるレシピ

numpy+jupyter+mtplotlib+sympy+scikit-learn

自分がよく使うpython環境(numpy+jupyter+mtplotlib+sympy+scikit-learn)を準備したコンテナ

Dockerfile
FROM python:3.11-slim

# 必要なライブラリをインストール
RUN pip install --no-cache-dir \
    numpy \
    jupyter \
    matplotlib \
    sympy \
    scikit-learn

# 作業ディレクトリ
WORKDIR /workspace

# デフォルトはbashに入る
CMD ["/bin/bash"]

を置いたディレクトリで、podman build -t my-python-lab ./でビルド完了。
作ったmy-python-labイメージから、対話可能で終了時自動削除されるコンテナを起動し、ホストのカレントディレクトリを /workspace にマウントし、Jupyterで使う8888ポートを外からアクセスできるようにするための実行コマンドが

podman run -it --rm -p 8888:8888 -v $(pwd):/workspace my-python-lab 

になる。Jupyter用の設定ファイルをホストに置いている場合は

podman run -it --rm -p 8888:8888 -v $(pwd):/workspace -v ~/.jupyter:/root/.jupyter   my-python-lab

として-v ~/.jupyter:/root/.jupyterを足すことで、起動時の設定をホストから持って来れる。例えばtoken書き写すの面倒で既にパスワード認証の設定を~/.jupyter以下に設定している場合など。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?