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
Related
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.
I have an Azure app service which is using docker-compose.yml file as it is multi-container docker app. It's docker-compose.yml file is given below:
version: '3.4'
services:
multiapp:
image: yogyogi/apps:i1
build:
context: .
dockerfile: MultiApp/Dockerfile
multiapi:
image: yogyogi/apps:i2
build:
context: .
dockerfile: MultiApi/Dockerfile
The app works pefectly with no issues. I can open it on the browser perfectly.
Now here starts the problem. I am trying to put an SSL Certficate for this app. I want to use volume and map it to inside the container. So i changed the docker-compose.yml file to:
version: '3.4'
services:
multiapp:
image: yogyogi/apps:i1
build:
context: .
dockerfile: MultiApp/Dockerfile
environment:
- ASPNETCORE_Kestrel__Certificates__Default__Password=mypass123
- ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx
volumes:
- SSL:/https
multiapi:
image: yogyogi/apps:i2
build:
context: .
dockerfile: MultiApi/Dockerfile
Here only the following lines are added to force the app to use aspnetapp.pfx as the SSL. This ssl should be mount to https folder of the container.
environment:
- ASPNETCORE_Kestrel__Certificates__Default__Password=mypass123
- ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx
volumes:
- SSL:/https/aspnetapp.pfx:ro
Also note that here SSL given on the volume is referring to Azure File Share. I have created an Azure Storage account (called 'myazurestorage1') and inside it created an Azure file share (called 'myfileshare1'). In this file share I created a folder by th name of ssl and uploaded my certificate inside this folder.
Then in the azure app service which contains the app running in docker compose. I did path mappings for this azure file share so that it can be used with your app. In the below screenshot see this:
I also tried the following docker-compose.yml file as given in official docs but no use:
version: '3.4'
services:
multiapp:
image: yogyogi/apps:i1
build:
context: .
dockerfile: MultiApp/Dockerfile
environment:
- ASPNETCORE_Kestrel__Certificates__Default__Password=mypass123
- ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx
volumes:
- ./mydata/ssl/aspnetapp.pfx:/https/aspnetapp.pfx:ro
multiapi:
image: yogyogi/apps:i2
build:
context: .
dockerfile: MultiApi/Dockerfile
volumes:
mydata:
driver: azure_file
driver_opts:
share_name: myfileshare1
storage_account_name: myazurestorage1
storageAccountKey: j74O20KrxwX+vo3cv31boJPb+cpo/pWbSy72BdSDxp/d7hXVgEoR56FVA7B+L6D/CnmdpIqHOhiEKqbuttLZAw==
But this does not works as app starts getting error. What is wrong and how to solve it?
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
I'm working on an ecommerce, I want to have the ability to upload product photos from the client and save them in a directory on the serve.
I implemented this feature but then I understood that since we use docker for our deployment, the directory in which I save the pictures won't persist. as I searched, I kinda realized that I should use volumes and map that directory in docker compose. I'm a complete novice backend developer (I work on frontend) so I'm not really sure what I should do.
Here is the compose file:
version: '3'
services:
nodejs:
image: node:latest
environment:
- MYSQL_HOST=[REDACTED]
- FRONT_SITE_ADDRESS=[REDACTED]
- SITE_ADDRESS=[REDACTED]
container_name: [REDACTED]
working_dir: /home/node/app
ports:
- "8888:7070"
volumes:
- ./:/home/node/app
command: node dist/main.js
links:
- mysql
mysql:
environment:
- MYSQL_ROOT_PASSWORD=[REDACTED]
container_name: product-mysql
image: 'mysql:5.7'
volumes:
- ../data:/var/lib/mysql
If I want to store the my photos in ../static/images (ralative to the root of my project), what should I do and how should refer to this path in my backend code?
Backend is in nodejs (Nestjs).
You have to create a volume and tell to docker-compose/docker stack mount it within the container specify the path you wamth. See the volumes to the very end of the file and the volumes option on nodejs service.
version: '3'
services:
nodejs:
image: node:latest
environment:
- MYSQL_HOST=[REDACTED]
- FRONT_SITE_ADDRESS=[REDACTED]
- SITE_ADDRESS=[REDACTED]
container_name: [REDACTED]
working_dir: /home/node/app
ports:
- "8888:7070"
volumes:
- ./:/home/node/app
- static-files:/home/node/static/images
command: node dist/main.js
links:
- mysql
mysql:
environment:
- MYSQL_ROOT_PASSWORD=[REDACTED]
container_name: product-mysql
image: 'mysql:5.7'
volumes:
- ../data:/var/lib/mysql
volumes:
static-files:{}
Doing this an empty container will be crated persisting your data and every time a new container mounts this path you can get the data stored on it. I would suggest to use the same approach with mysql instead of saving data within the host.
https://docs.docker.com/compose/compose-file/#volume-configuration-reference
I'm trying to run KrakenD image in Azure App Service.
KrakenD requires json config file krakend.json to be put into /etc/krakend/ (KrakenD image is based on Linux Alpine)
I created Web App for containers with the following docker-compose file:
version: "3"
services:
krakend:
image: devopsfaith/krakend:latest
volumes:
- ${WEBAPP_STORAGE_HOME}/site/krakend:/etc/krakend
ports:
- "8080:8080"
restart: always
Added storage account with a blob container where uploaded sample kraken.json file
In app configuration i added a path mapping like this:
But it looks like volume was not mounted correctly
2019-11-15 12:46:29.368 ERROR - Container create failed for
krakend_krakend_0_3032a936 with System.AggregateException, One or
more errors occurred. (Docker API responded with status
code=InternalServerError, response={"message":"invalid volume
specification: ':/etc/krakend'"} ) (Docker API responded with status
code=InternalServerError, response={"message":"invalid volume
specification: ':/etc/krakend'"} ) InnerException:
Docker.DotNet.DockerApiException, Docker API responded with status
code=InternalServerError, response={"message":"invalid volume
specification: ':/etc/krakend'"}
2019-11-15 12:46:29.369 ERROR - multi-container unit was not started
successfully
Additional questions
What does mean Mount path in Storage mounting? - i put there value /krankend
volume definition starts with ${WEBAPP_STORAGE_HOME} in docs they specified it as
volumes:
- ${WEBAPP_STORAGE_HOME}/site/wwwroot:/var/www/html
so i did it by analogy and tried all 3 possible paths
${WEBAPP_STORAGE_HOME}/site/wwwroot/krakend
${WEBAPP_STORAGE_HOME}/site/krakend
${WEBAPP_STORAGE_HOME}/krakend
but no luck - still getting the error
ERROR parsing the configuration file: '/etc/krakend/krakend.json'
(open): no such file or directory
finally resolved that with the following docker-compose file
version: "3"
services:
krakend:
image: devopsfaith/krakend:latest
volumes:
- volume1:/etc/krakend
environment:
WEBSITES_ENABLE_APP_SERVICE_STORAGE: TRUE
ports:
- "8080:8080"
restart: always
where volume1 is a blob storage mounted as the following
This did not work for me. I was getting Bind mount must start with ${WEBAPP_STORAGE_HOME}.
This worked. docker-compose.yml
version: "3"
services:
backend:
image: xxxx
ports:
- 80:80
volumes:
- vol1:/var/www/html/public
volumes:
vol1:
driver: local
Volume definition:
Name: vol1
Config: basic
Storage accounts: ...
Storage container: ...
Mount paht: /var/www/html/public