Downloading Files from Azure Container App to your Local Machine via Azure Blob Storage
Published Mar 22 2023 03:41 AM 15.1K Views
Microsoft

Azure Container Apps is a powerful tool for running containerized applications in the cloud. However, if you need to transfer files (custom log files, network captures, etc.) from your container app to another destination such as your local machine or Azure Blob Storage, you might find that the process is not as straightforward as you'd like.

In this post, we'll walk you through the steps to transfer files from your Azure Container App to Azure Blob Storage using the `curl` command. Once the file is present on your Blob Storage, you can easily download it to your local machine from the Azure Portal itself in case you need to analyze the logs or network traces with a local tool.

 

Step 1: Accessing the Azure Container App Console

To access the Azure Container App Console, navigate to your container app in the Azure Portal. Once you've selected your container app, click on the "Console" option under the "Monitoring" blade. This will open up a terminal window in your browser that you can use to connect to your container.

 

Step 2: Installing `curl`

Before you can transfer files using curl, you'll need to install it within your container. To install `curl`, simply enter the following command in the terminal window:

 

 

 

apt-get update && apt-get install -y curl

 

 

 

 

Step 3: Creating the `curl` Command

To transfer a file from your Azure Container App to Azure Blob Storage, you'll need to create a `curl` command that specifies the location of the file you want to transfer and the destination container and blob in Azure Blob Storage.

The curl syntax to upload a file to a Container within an Azure Blob Storage would look like this 

 

 

 

curl -X PUT -T [file_path] -H "x-ms-blob-type: BlockBlob" "https://[storage_account_name].blob.core.windows.net/[container_name]/[blob_name]?[sas_token]"

 

 

 

Make sure to replace the placeholders with the appropriate values:

  • [file_path] is the local file path of the file you want to upload.
  • [storage_account_name] is the name of your Azure Storage account.
  • [container_name] is the name of the container you want to upload the file to.
  • [blob_name] is the name of the blob you want to create or overwrite.
  • [sas_token] is a Shared Access Signature (SAS) token that provides permission to upload the file to the container. You can generate a SAS token with the appropriate permissions using the Azure portal or Azure CLI.

 

Here's an example command to upload a file named "example.txt" to a container named "mycontainer" into a storage account named "mystorageaccount" with a SAS token:

 

 

 

curl -X PUT -T example.txt -H "x-ms-blob-type: BlockBlob" "https://mystorageaccount.blob.core.windows.net/mycontainer/example.txt?[sas_token]"

 

 

 

 

Step 4: Executing the curl Command

Once you've created your `curl` command, you can execute it in the Azure Container App Console by pasting it into the terminal window and hitting enter. This will initiate the file transfer process and upload the specified file to Azure Blob Storage.

Nikhil_Vetteth_0-1679480267649.png

 

Step 5: Downloading the file from Azure Storage to your Local Machine

Once you've confirmed the file is in your Azure Blob Storage, you can simply browse to the Container within the Storage Account and download the file.

Nikhil_Vetteth_0-1679483085887.png

 

 

Note:- This post assumes you are not mounting a file share to your Container App, in case you are, you can simply 'mv' or 'cp' the file from whichever directory it is into the directory where you mounted the file share volume.

Co-Authors
Version history
Last update:
‎Mar 22 2023 04:08 AM
Updated by: