Search code examples
azureazure-container-serviceazure-appservice

Create volume for container running on Azure App Service Linux


We have a SpringBoot app which requires a keystore file located at "/secrets/app.keystore.jks" to run.

We want to run the app in a container on a Azure App Service Linux instance. And For security reasons we don't want to include the "/secrets/app.keystore.jks" file in the container itself. Instead, we have managed to upload the file to the "/home/site/wwwroot/secrets/" folder on the app service.

And we use the following command to start up the container on the app service

docker run -d myacr.azurecr.io/myAPp:latest -p 80:80 --name myApp 
-e WEBSITES_ENABLE_APP_SERVICE_STORAGE=TRUE -v /home/site/wwwroot/secrets:/secrets

In the app service's log, we have the error:

java.lang.IllegalStateException: java.io.IOException: Could not open /secrets/app.keystore.jks as a file, class path resource, or URL.

It looks to me the volume was not set up and the app cannot access to the file "/secrets/app.keystore.jks"

Does anyone know how to setup a volume so the app in the container can access a file on the host?


Solution

  • There are two ways to achieve your purpose. One is set the environment variable WEBSITES_ENABLE_APP_SERVICE_STORAGE as true and you can mount the persistent volume to your container like belowin the docker-compose file:

    volumes:
      - ${WEBAPP_STORAGE_HOME}/site/wwwroot/secrets:/secrets
    

    Get more details here.

    Another way is that you can mount the Azure Storage to your container and upload the files to the storage. Follow the steps here.