HapInS Developers Blog

HapInSが提供するエンジニアリングの情報サイト

Docker Desktopの代替 Podman Desktopを試してみた

はじめに

皆さん、Docker Desktopを使ったことがありますか?
Dockerを使うことで、1台のサーバー上に複数のアプリケーション実行環境(Dockerコンテナ)を作成・利用できるようになります。
アプリケーション実行環境(Dockerコンテナ)の他サーバーなどへの移転、他ユーザーとの共有が簡単に実行できるようになります。
しかし、Docker Desktopを商用利用する際は有料となってしまう可能性があります。
そこで、Docker Desktopの代替を利用することで、料金のことを気にせずに使用できないか検討してみました。
今回利用したPodman Desktopは、そのままではdockerコマンドとして使用することができなかったため、Docker Desktopと同様に利用できるように設定しました。

開発環境

  • macOS 11.6.1
  • Homebrew 4.1.12
  • Sudo version 1.9.5p2

Podman Desktopのインストール

1.以下のコマンドでPodman Desktopをインストールする
brew install podman-desktop
2.以下のコマンドでDocker-Composeをインストールする
brew install docker-compose
3.以下のコマンドでシンボリックリンクを作成する
ln -s /usr/local/bin/podman /usr/local/bin/docker
3ー1.以下のコマンドでシンボリックリンクが作成されたか確認する
readlink /usr/local/bin/docker

# /usr/local/bin/podman
4.以下のコマンドでイメージを全て表示しようとするとエラーが発生した(上記までで完了したと思ったが、甘くはなかった)
docker ps -a

# Cannot connect to Podman. Please verify your connection to the Linux system using `podman system connection list`, or try `podman machine init` and `podman machine start` to manage a new Linux VM
# Error: unable to connect to Podman socket: failed to connect: dial tcp 127.0.0.1:50950: connect: connection refused
5.4.のエラーメッセージに従い、まずは接続を確認してみる
docker system connection list

# Name                         URI                                                         Identity                                         Default
# podman-machine-default       ssh://core@127.0.0.1:50950/run/user/501/podman/podman.sock  /Users/[ユーザー名]/.ssh/podman-machine-default  true
# podman-machine-default-root  ssh://root@127.0.0.1:50950/run/podman/podman.sock           /Users/[ユーザー名]/.ssh/podman-machine-default  false
6.4.のエラーメッセージに従い、以下のコマンドを試してみる
docker machine init

# Error: podman-machine-default: VM already exists
7.4.のエラーメッセージに従い、以下のコマンドを試してみる
docker machine start

# Starting machine "podman-machine-default"
# Waiting for VM ...
# Mounting volume... /Users:/Users
# Mounting volume... /private:/private
# Mounting volume... /var/folders:/var/folders
# 
# This machine is currently configured in rootless mode. If your containers
# require root permissions (e.g. ports < 1024), or if you run into compatibility
# issues with non-podman clients, you can switch using the following command: 
# 
#   podman machine set --rootful
# 
# API forwarding listening on: /Users/[ユーザー名]/.local/share/containers/podman/machine/qemu/podman.sock
# 
# The system helper service is not installed; the default Docker API socket
# address can't be used by podman. If you would like to install it run the
# following commands:
# 
#   sudo /usr/local/Cellar/podman/4.6.2/bin/podman-mac-helper install
#   podman machine stop; podman machine start
# 
# You can still connect Docker API clients by setting DOCKER_HOST using the
# following command in your terminal session:
# 
#   export DOCKER_HOST='unix:///Users/[ユーザー名]/.local/share/containers/podman/machine/qemu/podman.sock'
# 
# Machine "podman-machine-default" started successfully
8.以下のコマンドで起動を止めてみる
docker machine stop

# Waiting for VM to exit...
# Machine "podman-machine-default" stopped successfully
9.7.でsystem helper serviceがインストールされていないと出ているため、メッセージに従いインストールしてみる
sudo /usr/local/Cellar/podman/4.6.2/bin/podman-mac-helper install

CentOS 7 のイメージを取得し、Bashコマンド待ち受け状態にする

1.以下のコマンドでCentOS 7 のイメージを取得
docker pull centos:centos7

# Resolved "centos" as an alias (/etc/containers/registries.conf.d/000-shortnames.conf)
# Trying to pull quay.io/centos/centos:centos7...
# Getting image source signatures
# Copying blob sha256:2d473b07cdd5f0912cd6f1a703352c82b512407db6b05b43f2553732b55df3bc
# Copying config sha256:8652b9f0cb4c0599575e5a003f5906876e10c1ceb2ab9fe1786712dac14a50cf
# Writing manifest to image destination
# 8652b9f0cb4c0599575e5a003f5906876e10c1ceb2ab9fe1786712dac14a50cf
2.以下のコマンドでDockerイメージを一覧表示し、CentOS が取得できたことを確認する
docker images

# REPOSITORY             TAG         IMAGE ID      CREATED      SIZE
# quay.io/centos/centos  centos7     8652b9f0cb4c  2 years ago  212 MB
3.docker run コマンドを実行して、コンテナにcentos7 という名前をつけ、コンテナを作成・起動する
docker run -it -d --name centos7 centos:centos7

# 13d2472b75b8d264474ea7c06cc6332263edd38af2cf405b0d292d2061799158
3ー1.PCを再起動などでコンテナが停止していた場合は、以下のコマンドでコンテナを起動する
docker start centos7

# centos7
4.以下のコマンドで起動中のコンテナをし、コンテナが起動されていることを確認する
docker ps

# CONTAINER ID  IMAGE                          COMMAND     CREATED         STATUS         PORTS       NAMES
# 13d2472b75b8  quay.io/centos/centos:centos7  /bin/bash   32 seconds ago  Up 31 seconds              centos7
5.CentOS 7 コンテナ内の Bash を実行し、コマンド待ち受け状態にする
docker exec -it centos7 /bin/bash
6.以下のコマンドでCentOS のバージョンを確認する
cat /etc/redhat-release

# CentOS Linux release 7.9.2009 (Core)

Dockerのコンテナやイメージなどを削除する

以下の記事にまとめました

blog.hapins.net