Azure VM で Docker イメージを作成して Azure コンテナー レジストリ に登録する
Azure VM で Docker イメージを作成して Azure コンテナー レジストリ に登録する手順を解説します。
👇これより先は下記記事の内容を前提とします
Docker をAzure VM(Ubuntu)にインストールする
# Add Docker's official GPG key:
sudo apt-get -y update
sudo apt-get -y install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get -y update
# Install the Docker packages
sudo apt-get -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
ログインユーザへの権限付与
sudo usermod -G docker admin01
sudo su - admin01
動作確認
sudo docker run hello-world
👇下記メッセージが出力されることを確認します。
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
カスタムイメージの作成
👇nginxのイメージを起動
docker run -it --rm -d --network host --name web nginx
👇http(80)ポートの解放
az vm open-port^
--resource-group sampleResourceGroup^
--name ubuntu-vm^
--port 80
👇ブラウザからVMのIPへのhttpアクセスを確認します。
http://***.***.***.***/
👇こんな画面が表示されます。
👇nginxのイメージを停止
docker stop web