How to mount a docker volume in Azure with docker compose YAML - azure

I'm attempting to deploy a PosgreSQL Docker container in Azure. To that end, I created in Azure a storage account and a file share to store a Docker volume.
Also, I created the Docker Azure context and set it as default.
To create the volume, I run:
volume create volpostgres --storage-account mystorageaccount
I can verify that the volume was created with docker volume ls.
ID DESCRIPTION
mystorageaccount/volpostgres Fileshare volpostgres in mystorageaccount storage account
But when I try to deploy with docker compose up, I get
could not find volume source "volpostgres"
This is the YAML file that does not work. How to fix it? how to point to the volume correctly?
version: '3.7'
services:
postgres:
image: postgres:13.1
container_name: cont_postgres
networks:
db:
ipv4_address: 22.225.124.121
ports:
- "5432:5432"
environment:
POSTGRES_PASSWORD: xxxxx
volumes:
- volpostgres:/var/lib/postgresql/data
networks:
db:
driver: bridge
ipam:
driver: default
config:
- subnet: 22.225.124.121/24
volumes:
volpostgres:
name: mystorageaccount/volpostgres

You can follow the steps here. And the volumes part in the docker-compose file needs to be changed into this:
volumes:
volpostgres:
driver: azure_file
driver_opts:
share_name: myfileshare
storage_account_name: mystorageaccount

Related

How to set configuration files using docker compose with Azure Container Instance

I have a docker compose file that I use for local development but I need to deploy this on Azure Containers. The docker compose I use on local is this:
version: "3.4"
services:
zipkin-all-in-one:
image: openzipkin/zipkin:latest
ports:
- "9411:9411"
otel-collector:
image: otel/opentelemetry-collector:latest
command: ["--config=/etc/otel-collector-config.yaml"]
volumes:
- ./otel-collector-config.yaml:/etc/otel-collector-config.yaml
ports:
- "8888:8888"
- "8889:8889"
- "4317:4317"
depends_on:
- zipkin-all-in-one
seq:
image: datalust/seq:latest
environment:
- ACCEPT_EULA=Y
ports:
- "80:80"
- "5341:5341"
And this one is working fine. Actually I could make Zipkin and Seq work with Azure, the problem is open telemetry. It needs a configuration file to work, so I did the follow:
Created an azure file storage
Added Opentelemetry yaml file into this storage
Changed Docker compose file as the follows to point this volume
version: "3.4"
services:
#zipkin here
otel-collector:
image: otel/opentelemetry-collector:latest
command: ["--config=/etc/otel-collector-config.yaml"]
volumes:
- mydata:/mounts/testvolumes
ports:
- "8888:8888"
- "8889:8889"
- "4317:4317"
depends_on:
- zipkin-all-in-one
# seq here
volumes:
mydata:
driver: azure_file
driver_opts:
share_name: testvolume
storage_account_name: storageqwricc
You can see in this image that everything is running but otel.
I'm almost sure that the problem is it can't find otel configuration file. The error that appears in Logs:
Error: Failed to start container otel-collector, Error response: to create containerd task: failed to create shim task: failed to create container ddf9fc55eee4e72cc78f2b7857ff735f7bc506763b8a7ce62bd9415580d86d07: guest RPC failure: failed to create container: failed to run runc create/exec call for container ddf9fc55eee4e72cc78f2b7857ff735f7bc506763b8a7ce62bd9415580d86d07 with exit status 1: container_linux.go:380: starting container process caused: exec: stat no such file or directory: unknown
And this is my azure file storage.
I've tried different paths. Checked permission file. Running without OTEL and it works as expected.
Also tried this configuration from other thread:
volumes:
- name: mydata
azureFile:
share_name: testvolume
readOnly: false
storageAccountName: storageqwricc
storageAccountKey: mysecretkey

Azure WebApps + Azure File share with multicontainers

I have been trying to setup my Postgresql db with my API. My API is on Azure WebApps and db on Azure fileshare.
The following is my docker compose file
version: '3.3'
services:
db:
image: postgres
volumes:
- db_path:/var/lib/postgresql/data
restart: always
environment:
POSTGRES_USER: dbuser
POSTGRES_PASSWORD: dbuser's_password
POSTGRES_DB: db_1
api:
depends_on:
- db
image: <my registry>.azurecr.io/api:latest
ports:
- "80:80"
restart: always
My WebApp -> Configuration -> Path mappings is below
It did get deployed but I couldn't find my database files in my Azure fileshare's location. Now as I am redeploying, I can see the following in the Log Stream.
Can somebody show me where did I do wrong? Why my DB is not in my Azure fileshare?
Thanks in advance
Edit:
Along with what Charles suggested as below:
I also have updated my docker-compose.yml file as below. The changes I made is I kept my volume name same as mapping name and added driver_opts:
version: '3.8'
services:
db:
image: mysql
volumes:
- mysql:/var/lib/mysql
environment:
- MYSQL_DATABASE=dbName
- MYSQL_ROOT_PASSWORD=MyRootPassword!
- MYSQL_USER=dbUser_1
- MYSQL_PASSWORD=dbUser_1'sPassword
restart: always
api:
depends_on:
- db
entrypoint: ["./wait_for.sh", "db:3306", "-t", "3600", "--", "execute", "api"] #waiting very long enough to set the db server up and running
image: <my registry's url>/api:latest
ports:
- "80:80"
restart: always
volumes:
mysql:
driver: azure_file
driver_opts:
share_name: Azure_Share_Name
storage_account_name: Azure_Storage_Account_Name
storageaccountkey: Azure_Key
This is a known issue. When you mount using the persistent volume with Azure File Share, then the mount path will have the root owner and group, and you can't change it. So it the application needs the path with a special user, like this issue, the Postgresql needs the mount path /var/lib/postgresql/data having postgres owner, then it can't be achieved.
Note that the screenshot you provide with the path mapping shows the wrong mount path with the configuration in your YAML file. It may be a mistake.

Azure_file for docker composer in Azure cloud

Trying to create ChirpStack Docker-Compose container in Azure cloud:
docker login azure
docker context create aci myacicontext
docker context use myacicontext
docker compose --file .\docker-compose.yml up
Got error:
cannot use ACI volume, required driver is “azure_file”, found “”
What I do wrong?
UPD
Content of docker-compose.yml:
version: "3"
services:
chirpstack-network-server:
image: chirpstack/chirpstack-network-server:3
volumes:
- ./configuration/chirpstack-network-server:/etc/chirpstack-network-server
chirpstack-application-server:
image: chirpstack/chirpstack-application-server:3
ports:
- 8080:8080
volumes:
- ./configuration/chirpstack-application-server:/etc/chirpstack-application-server
chirpstack-gateway-bridge:
image: chirpstack/chirpstack-gateway-bridge:3
ports:
- 1700:1700/udp
volumes:
- ./configuration/chirpstack-gateway-bridge:/etc/chirpstack-gateway-bridge
chirpstack-geolocation-server:
image: chirpstack/chirpstack-geolocation-server:3
volumes:
- ./configuration/chirpstack-geolocation-server:/etc/chirpstack-geolocation-server
postgresql:
image: postgres:9.6-alpine
environment:
- POSTGRES_PASSWORD=root
volumes:
- ./configuration/postgresql/initdb:/docker-entrypoint-initdb.d
- postgresqldata:/var/lib/postgresql/data
redis:
image: redis:5-alpine
volumes:
- redisdata:/data
mosquitto:
image: eclipse-mosquitto:2
ports:
- 1883:1883
volumes:
- ./configuration/eclipse-mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf
volumes:
postgresqldata:
redisdata:
The error already shows you that it requires the driver azure_file for the volume when you use the Azure file share as the persistent volume. It should be like this:
volumes:
postgresqldata:
driver: azure_file
driver_opts:
share_name: myfileshare
storage_account_name: mystorageaccount
redisdata:
driver: azure_file
driver_opts:
share_name: myfileshare
storage_account_name: mystorageaccount
See more details about the File Share for the ACI through Docker Compose here.

Mount azure storage account in docker-compose

How can I Mount azure storage account as a volume in the docker-compose?
I checked this driver but it's deprecated and the link provided there, & it is inactive.
docker-compose.yml
version: '3.3'
services:
web:
image: web:74
ports:
- "3000:3000"
volumes:
logvolume01: {}
You can just pass the url of the blob path,
volumes:
- ${WEBAPP_STORAGE_HOME}/zoo1/data:/data
here is an example

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

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?
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/
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

Resources