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?

More than 1 year has passed since last update.

Docker Desktop の代わりに docker コマンドを使用して Azure Container Instances を操作してみた

Posted at

背景と目的

Docker Desktop の企業利用が有料になったのを機に、私は会社 PC からアンインストールしてしまいました。それでもたまに docker コマンドを使って検証したい時が発生します。WSL のインストールも禁止されている PC なので、Azure 上の検証用 AVD につないで docker コマンドを使った検証をしていたります。今回は Docker Desktop の代わりに docker コマンドを使用して Azure Container Instances を操作してみました。

前提条件

bash
$ sw_vers
ProductName:    macOS
ProductVersion: 12.5
BuildVersion:   21G72

$ az version
{
  "azure-cli": "2.39.0",
  "azure-cli-core": "2.39.0",
  "azure-cli-telemetry": "1.0.6",
  "extensions": {}
}

$ docker --version
Docker version 20.10.17, build 100c701

# Docker Desktop は停止した状態で動作を確認しました
$ docker ps
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

検証内容

bash
# 環境変数をセットします
region=japaneast
prefix=mnrdaci

# リソースグループを作成します
az group create --name ${prefix}-rg --location $region

# Azure にログインします(ブラウザが開きます)
docker login azure

# ACI に関連付けられた Docker コンテキストを作成します
docker context create aci ${prefix} --resource-group ${prefix}-rg

# Docker コンテキスト一覧を表示します
docker context ls

# 作成したコンテキストで Nginx コンテナを実行します
docker --context ${prefix} run --name ${prefix} -d -p 80:80 nginx

# リソースグループ内に ACI リソースが作成されたのを確認します
az resource list --resource-group ${prefix}-rg --output table

# ACI のパブリック IP アドレスを取得します
pip=$(az container show --name ${prefix} --resource-group ${prefix}-rg --query ipAddress.ip --output tsv)

# ACI にアクセス出来るか試します
curl $pip

# アクセスログを確認します
docker --context ${prefix} logs ${prefix}

# コンテナを停止します
docker --context ${prefix} stop ${prefix}

# コンテナを削除します
docker --context ${prefix} rm ${prefix}

# リソースグループ内に ACI リソースが無くなったのを確認します
az resource list --resource-group ${prefix}-rg --output table

# Docker コンテキストを削除します
docker context rm ${prefix}

# Docker コンテキスト一覧を表示します
ddocker context ls

# リソースグループを削除します
az group delete --name ${prefix}-rg --yes

参考

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?