How do I map an Azure File Share as a volume in a Docker Compose file?
Asked Answered
L

2

7

I have so far only found examples on how to create a volume on the host machine, e.g:

version: "3.3"
services:
  mysql:
    image: mysql
    volumes:
       - db-data:/var/lib/mysql/data
volumes:
  db-data:

So this defines a volume named db-data that will physically be stored on the host machine running the container.

Is is possible to makes the db-data volume point to an Azure File Share in an Azure Storage account and how would I specify the needed parameters?

Licentiate answered 20/6, 2018 at 10:35 Comment(0)
H
1

The format that works for me currently is:

version: "3.8"

volumes:
  db-data:
    driver: azure_file
    driver_opts:
      share_name: myfileshare
      storage_account_name: mystorageaccount
Homoeo answered 31/1, 2021 at 5:27 Comment(2)
what about the account key etc? There isn't enough info specified here to connect securely so how does that work - any tips?Camacho
This answer is for container instance service, not app service I think.Biometrics
C
0

From CLI you can create with:

docker volume create -d azurefile -o share=myvol --name vol1 

docker run -i -t -v vol1:/data busybox    

In your compose you need to use this skeleton:

volumes:
  myvol:
    driver: azurefile
    driver_opts:
      accountname: ___your__account_name
      accountkey: ___your_account_key
      share: "volumes"
      remotepath: "myvol"

UPDATE:

These options are now deprecated, please follow instruction for CloudStor plugin at: https://docs.docker.com/docker-for-azure/persistent-data-volumes/

Chancey answered 21/6, 2018 at 7:21 Comment(8)
Yes, I know how to do it on the command line, but how do I create a volume in a docker compose file?Sanyu
I added info to my answerChancey
In my scenario (Azure Web App for Containers) I cannot run anything, I can only upload a docker compose file. So can I create a volume using a docker compose file?Sanyu
Hi Nicola, I tried the compose file skeleton you have here but it complained that accountname and accountkey are not recognised volume drive options. Any idea why?Schnook
The CloudStor documentation linked doesn't talk about a compose file.....Acropolis
Docker Docs link is now dead, having trouble locating a replacement.Judenberg
@MathiasRönnlund here is the Azure guide for storage with app service containers: learn.microsoft.com/en-us/azure/app-service/containers/…Suint
How do I do that while this option is now deprecated?Psoriasis

© 2022 - 2024 — McMap. All rights reserved.