title | description | services | author | ms.service | ms.custom | ms.topic | ms.date | ms.author | zone_pivot_groups | ||
---|---|---|---|---|---|---|---|---|---|---|---|
Quickstart: Build and deploy your app from your local filesystem to Azure Container Apps |
Build your container app from local source and deploy in Azure Container Apps using az containerapp up. |
container-apps |
craigshoemaker |
container-apps |
|
quickstart |
01/27/2024 |
cshoe |
container-apps-code-to-cloud-segmemts |
This article demonstrates how to build and deploy a microservice to Azure Container Apps from local source code using the programming language of your choice. In this quickstart, you create a backend web API service that returns a static collection of music albums.
Note
This sample application is available in two versions. One version where the source contains a Dockerfile. The other version has no Dockerfile. Select the version that best reflects your source code. If you are new to containers, select the No Dockerfile option at the top.
The following screenshot shows the output from the album API service you deploy.
:::image type="content" source="media/quickstart-code-to-cloud/azure-container-apps-album-api.png" alt-text="Screenshot of response from albums API endpoint.":::
To complete this project, you need the following items:
Requirement | Instructions |
---|---|
Azure account | If you don't have one, create an account for free. You need the Contributor or Owner permission on the Azure subscription to proceed. Refer to Assign Azure roles using the Azure portal for details. |
Azure CLI | Install the Azure CLI. |
[!INCLUDE container-apps-create-cli-steps.md]
Now that your Azure CLI setup is complete, you can define the environment variables that are used throughout this article.
Define the following variables in your bash shell.
export RESOURCE_GROUP="album-containerapps"
export LOCATION="canadacentral"
export ENVIRONMENT="env-album-containerapps"
export API_NAME="album-api"
Define the following variables in your PowerShell console.
$RESOURCE_GROUP="album-containerapps"
$LOCATION="canadacentral"
$ENVIRONMENT="env-album-containerapps"
$API_NAME="album-api"
Download and extract the API sample application in the language of your choice.
::: zone pivot="with-dockerfile"
Download the source code to your machine.
Extract the download and change into the containerapps-albumapi-csharp-main/src folder.
Download the source code to your machine.
Extract the download and change into the containerapps-albumapi-java-main/src folder.
Download the source code to your machine.
Extract the download and change into the containerapps-albumapi-javascript-main/src folder.
Download the source code to your machine.
Extract the download and change into the containerapps-albumapi-python-main/src folder.
Download the source code to your machine.
Extract the download and navigate into the containerapps-albumapi-go-main/src folder.
::: zone-end ::: zone pivot="without-dockerfile"
Download the source code to your machine.
Extract the download and change into the containerapps-albumapi-csharp-buildpack/src folder.
Download the source code to your machine.
Extract the download and change into the containerapps-albumapi-java-buildpack folder.
Note
The Java Buildpack uses Maven with default settings to build your application. Alternatively, you can the use --build-env-vars
parameter to configure the image build from source code.
Download the source code to your machine.
Extract the download and change into the containerapps-albumapi-javascript-buildpack/src folder.
Download the source code to your machine.
Extract the download and change into the containerapps-albumapi-python-buildpack/src folder.
Azure Container Apps cloud build doesn't currently support Buildpacks for Go.
::: zone-end
Build and deploy your first container app with the containerapp up
command. This command will:
::: zone pivot="with-dockerfile"
- Create the resource group
- Create an Azure Container Registry
- Build the container image and push it to the registry
- Create the Container Apps environment with a Log Analytics workspace
- Create and deploy the container app using the built container image ::: zone-end
::: zone pivot="without-dockerfile"
- Create the resource group
- Create a default registry as part of your environment
- Detect the language and runtime of your application and build the image using the appropriate Buildpack
- Push the image into the Azure Container Apps default registry
- Create the Container Apps environment with a Log Analytics workspace
- Create and deploy the container app using the built container image ::: zone-end
::: zone pivot="with-dockerfile"
The up
command uses the Dockerfile in the root of the repository to build the container image. The EXPOSE
instruction in the Dockerfile defined the target port, which is the port used to send ingress traffic to the container.
::: zone-end ::: zone pivot="without-dockerfile"
If the up
command doesn't find a Dockerfile, it automatically uses Buildpacks to turn your application source into a runnable container. Since the Buildpack is trying to run the build on your behalf, you need to tell the up
command which port to send ingress traffic to.
::: zone-end
In the following code example, the .
(dot) tells containerapp up
to run in the src
directory of the extracted sample API application.
::: zone pivot="with-dockerfile"
az containerapp up \
--name $API_NAME \
--location $LOCATION \
--environment $ENVIRONMENT \
--source .
::: zone-end ::: zone pivot="without-dockerfile"
az containerapp up \
--name $API_NAME \
--location $LOCATION \
--environment $ENVIRONMENT \
--ingress external \
--target-port 8080 \
--source .
Important
In order to deploy your container app to an existing resource group, include --resource-group yourResourceGroup
to the containerapp up
command.
::: zone-end
::: zone pivot="with-dockerfile"
az containerapp up `
--name $API_NAME `
--resource-group $RESOURCE_GROUP `
--location $LOCATION `
--environment $ENVIRONMENT `
--source .
::: zone-end ::: zone pivot="without-dockerfile"
az containerapp up `
--name $API_NAME `
--resource-group $RESOURCE_GROUP `
--location $LOCATION `
--environment $ENVIRONMENT `
--ingress external `
--target-port 8080 `
--source .
::: zone-end
Copy the FQDN to a web browser. From your web browser, go to the /albums
endpoint of the FQDN.
:::image type="content" source="media/quickstart-code-to-cloud/azure-container-apps-album-api.png" alt-text="Screenshot of response from albums API endpoint.":::
The maximum size for uploading source code is 200MB. If the upload goes over the limit, error 413 is returned.
If you're not going to continue on to the Deploy a frontend tutorial, you can remove the Azure resources created during this quickstart with the following command.
Caution
The following command deletes the specified resource group and all resources contained within it. If the group contains resources outside the scope of this quickstart, they are also deleted.
az group delete --name $RESOURCE_GROUP
az group delete --name $RESOURCE_GROUP
Tip
Having issues? Let us know on GitHub by opening an issue in the Azure Container Apps repo.
After completing this quickstart, you can continue to Tutorial: Communication between microservices in Azure Container Apps to learn how to deploy a front end application that calls the API.
[!div class="nextstepaction"] Tutorial: Communication between microservices