部署至雲端Deploy to the cloud
現在您已在本機執行您的應用程式,您可以開始思考如何在雲端中執行應用程式,讓其他人可以存取並使用它。Now that you have run your app locally, you can start to think about running it in the cloud so other people can access it and make use of it. 若要這樣做,您將使用 Docker 內容。To do this, you'll use Docker contexts. 內容是您目前正在使用容器的位置。A context is the place where you're currently working with containers. 現在,您只會有「預設」內容,因此您必須新增雲端應用程式,並將您的應用程式部署到其中。Right now, you only have your "default" context, so you'll need to add a cloud one and deploy your app to it.
建立您的雲端內容Create your cloud context
若要開始,您可以查看 Docker 面板的 [內容] 區段來查看您擁有的內容:To start, you can see what contexts you have by looking at the contexts section of the Docker panel:
您應該只會看到本機工作的預設內容。You should only see your default context for local work.
若要部署至雲端,您需要建立新的 ACI 內容,但若要這樣做,您必須先使用 Azure 帳戶擴充功能來向 Azure 進行驗證。To deploy to the cloud, you need to create a new ACI context, but to do this, you first need the Azure account extension to authenticate with Azure.
如果您還沒有 Azure 帳戶,您必須設定一個。You'll need to set up an Azure account if you don’t already have one.
現在您可以建立新的 ACI 內容。Now you can create your new ACI context. 若要這麼做,您可以按一下 Docker view 內容區段上的加號 按鈕。You can do this by clicking the plus button on the Contexts section of the Docker view.
這會詢問您要執行這些容器的資源群組。This will ask you what resource group you want to run these containers under. 您可以使用方向鍵來選取現有的群組,或使用預設選項來使用新的群組。Either select an existing group using the arrow keys, or use the default option to use the new group.
您現在可以看到列出的 ACI 內容,並可在其上按一下滑鼠右鍵,使其成為目前的焦點/使用內容:You can now see your ACI context listed and can right-click it to make it your current focus/in use context:
在雲端中執行容器Run containers in the cloud
現在,使用 ACI 內容並執行容器。Now, use your ACI context and run the container.
docker context use myacicontext docker run -dp 3000:3000 <username>/getting-started
執行這項操作後,現在請查看您內容中的容器。Having run this, now look at the container in your context.
若要檢查這項作業是否正常運作,您可以在執行中的容器上按一下滑鼠右鍵,然後選擇 [ 在瀏覽器中顯示]。To check this is all working properly, you can right-click on the running container and choose View in browser.
而且,您可以看到容器是在公用 IP 中執行,而且運作正常!And, you can see that the container is running in a public IP and working correctly!
- 現在,您可以查看執行中的容器,以瞭解其運作方式。Now, you can have a look at our running container to see how it is working. 您可以從查看容器記錄開始:You can start by having a look at the container logs:
docker logs distracted-jackson
- 您也可以執行到容器中,就像使用本機容器一樣。You can also exec into your container as you would with a local container.
docker exec -it distracted-jackson sh
- 最後,若要清除您的工作空間,並確保您不會被收取繼續執行測試容器的費用,只要以滑鼠右鍵按一下執行中的容器,然後選擇 [ 移除] 即可。Lastly to clean up your working space and to make sure you're not being charged for continuing to run the test container, you can simply right-click on the running container and choose Remove.
概括回顧Recap
很棒的是,您現在已完成工作負載,並在第一次成功部署至雲端。Fantastic, you've now taken your workload and deployed it to the cloud successfully for the first time. 您也可以從命令列使用,也可以使用執行 docker run
docker compose up
多容器應用程式,在您的 ACI 內容中執行所有這項作業。You can do all of this from the command line as well from within your ACI context using docker run
and also using docker compose up
to run your multi-container applications. 若要深入瞭解如何在雲端中執行容器,請閱讀 有關使用 ACI的擴充檔。To find out more about running your containers in the cloud, read through the extended documentation on using ACI.
後續步驟Next steps
繼續進行本教學課程!Continue with the tutorial!