LoginSignup
1
1

More than 3 years have passed since last update.

DockerコンテナからAzure PowerShellを実行する

Posted at

今更ながらDockerに触れてみましたのでAzure PowerShellをDockerコンテナから実行してみます。

実行環境

  • WSL2(Ubuntu)
  • Docker Desktop for Windows

コンテナの作成

Docker HubでMicrosoft社公式のイメージが提供されていますのでこちらを使用します。

https://hub.docker.com/_/microsoft-azure-powershell

コンテナ作成手順も公開されていますので手順に従っていきます。
https://docs.microsoft.com/ja-jp/powershell/azure/azureps-in-docker?view=azps-3.7.0

まずはイメージの取得。

sudo docker pull mcr.microsoft.com/azure-powershell

Using default tag: latest
latest: Pulling from azure-powershell
5bed26d33875: Pull complete
f11b29a9c730: Pull complete
930bda195c84: Pull complete
78bf9a5ad49e: Pull complete
3183894b4ae2: Pull complete
5d930b42a49c: Pull complete
95d0de46cc6e: Pull complete
9bab5da02730: Pull complete
Digest: sha256:c06ab1162d6236b053ab425e54fb9f1feca0d6385865dd6e5c225076732007ad
Status: Downloaded newer image for mcr.microsoft.com/azure-powershell:latest
mcr.microsoft.com/azure-powershell:latest

対話モードでコンテナを作成。
PowerShellのバージョンは7.0でした。

sudo docker run -it mcr.microsoft.com/azure-powershell pwsh
PS /> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.0.0
PSEdition                      Core
GitCommitId                    7.0.0
OS                             Linux 4.19.84-microsoft-standard #1 SMP Wed Nov 13 11:44:37 UTC 2019
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Azure PowerShellの実行

Azureにログインしてみます。

PS /> Login-AzAccount
WARNING: To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code xxxxxxxx to authenticate.

PowerShell Coreのため、アカウント選択前に認証が必要です。
メッセージのURLにブラウザでアクセスし認証コードを入力します。
認証コード入力後の次の画面でログインするAzureアカウントを選択してください。

無事にログインできました。

Account    SubscriptionName TenantId                          Environment
-------    ---------------- --------                          -----------
xxxxxxxxxx subscriptionA    xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx AzureCloud

VMを起動してみます。

PS /> Start-AzVM -ResourceGroupName hoge-rg -Name hoge-vm

OperationId : 02ef9231-7972-4fc8-880c-5367c0c59d37
Status      : Succeeded
StartTime   : 4/5/2020 3:32:14 PM
EndTime     : 4/5/2020 3:34:31 PM
Error       :

やったぜ(起動できました。)

まとめ

少ない手順で簡単に作成、実行できました。
イメージも公式から提供されていますので安心ですね。
次はAzure上にコンテナを作って実行してみたいと思ってます。

1
1
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
1
1