5 minute read

In this guide I’ll show how to mount Volumes to Docker Images in Azure WebApp for Containers.

This is slightly documented in the Azure documentation but I feel it left some vital info out.

Let’s say you want to host a service in a Azure WebApp for Containers, for example TeamCity.

Team Citys docker image requires that you have a few paths persisted.

The docs in DockerHub says to start the image with the following startup command:

docker run --name teamcity-server-instance  \
    -v <path-to-data-directory>:/data/teamcity_server/datadir \
    -v <path-to-logs-directory>:/opt/teamcity/logs  \
    -p <port-on-host>:8111 \
    jetbrains/teamcity-server

But Azure WebApps do not allow you to specify a startup command for the docker image. -v is a volume mount command, to map a path on the host machine to a path on in the docker image. So how do we run these -v commands?

Three ways to mount volumes

I found three ways to mount voulmes documented in various ways on the world wide webs. I suggest using the first one if you only have one container

Alternative A: Mounting using Path Mappings when running one docker container

The best way to mount volumes to a docker image if you use a single container.

Find Web App" -> "Deployment Center" -> "Docker Compose and ensure you have selected Single Container, and use the Docker image you need.

Then go to Web App -> Configuration -> Path Mappings

Create a new Azure Storage Mount mapping.

Name: tcdata // This name can be anything, but keep it simple and lower case.
Mount path: /data/teamcity_server/datadir
// Mount path is the path within the docker image you want to mount to.
// For example in the docker image for teamcity we need a data directory mount.

Repeat the above for all volume paths you need. Remember to press Save after.

You can now restart the application and the mounts should automatically mount to the correct folder within the single docker image you use.

Alternative B: Mounting using AppService Storage and Docker Compose

If you dont want to use an external drive you can mount the AppService storage.

To enable app service storage you need to add the following setting to the AppService Configuration (it may be there, just switch from false to true if it exists):

WEBSITES_ENABLE_APP_SERVICE_STORAGE=true

You then have to use the Docker Compose mapping, example found in this section:

Find Web App -> Deployment Center -> Docker Compose

This requires the use of a compose file with a single container. This limits the usefulness of the AppService, but you are now able to mount paths from the host into the container.

NB: The host path must start with ${WEBAPP_STORAGE_HOME}/.

version: '3.7'
services:
   teamcity:
     image: jetbrains/teamcity-server:latest
     volumes:
       - ${WEBAPP_STORAGE_HOME}/tc:/data/teamcity_server/datadir
       - ${WEBAPP_STORAGE_HOME}/tc-logs:/opt/teamcity/logs
     restart: always

Alternative C: Mounting using Path Mappings and Docker Compose

To use docker compose with path mappings do the same as in Alternative B, but mount Path Mappings.

Go to WebApp -> Configuration -> Path Mappings

Create a new Azure Storage Mount mapping.

Name: This name is used to identify the volume. Example: `data`
Mount path: If you use docker compose this path can be anything. For instance `/tc-data`.

Find “Web App” -> “Deployment Center” -> “Docker Compose”

You can then create a compose file with one container, to easily map the volumes to a path using the volume Name

version: '3.7'
services:
   teamcity:
     image: jetbrains/teamcity-server:latest
     volumes:
       - data:/data/teamcity_server/datadir #<- the volume Name here is the same as the Name used above when creating the Storage Mount Mapping
       - logs:/opt/teamcity/logs
     restart: always

The end

You should now know how to mount directories for docker containers hosted in Azure Web Apps for Containers.

That’s it for now!

// Nils Henrik

Tags:

Categories:

Updated: