I am trying to deploy a Node SDK on azure app service through docker container. In my sdk, I have mounted a connection file & written a docker-compose for this. But when I deploy it by azure I get below error.
InnerException: Docker.DotNet.DockerApiException, Docker API responded with status code=InternalServerError, response={"message":"invalid volume specification: ':/usr/src/app/connection.json'"}
docker-compose.yml
version: '2'
services:
node:
container_name: node
image: dhiraj1990/node-app:latest
command: [ "npm", "start" ]
ports:
- "3000:3000"
volumes:
- ${WEBAPP_STORAGE_HOME}/site/wwwroot/connection.json:/usr/src/app/connection.json
connection.json is present at this path /site/wwwroot
.
Dockerfile
FROM node:8
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./
RUN npm install
# If you are building your code for production
# RUN npm ci --only=production
# Bundle app source
COPY . .
EXPOSE 3000
Please tell me what is the issue ?
In the Azure portal, navigate to the app. From the left navigation, click Configuration > Path Mappings > New Azure Storage Mount.
To mount multiple volumes in a container instance, you must deploy using an Azure Resource Manager template, a YAML file, or another programmatic method. To use a template or YAML file, provide the share details and define the volumes by populating the volumes array in the properties section of the file.
When building an image, you can't mount a volume. However, you can copy data from another image! By combining this, with a multi-stage build, you can pre-compute an expensive operation once, and re-use the resulting state as a starting point for future iterations.
If WEBSITES_ENABLE_APP_SERVICE_STORAGE setting is unspecified or set to false, the /home/ directory will not be shared across scale instances, and files written will not persist across restarts. Explicitly setting WEBSITES_ENABLE_APP_SERVICE_STORAGE to true will enable the mount.
Update:
The problem is that you cannot mount a file to the persistent storage, it should be a directory. So the correct volumes should set like below:
volumes:
- ${WEBAPP_STORAGE_HOME}/site/wwwroot:/usr/src/app
And you also need to enable the persistent storage in your Web app for the container by setting the environment variable WEBSITES_ENABLE_APP_SERVICE_STORAGE=TRUE
. For more details, see Add persistent storage.
The persistent storage is just used to persist your data from your container. And if you want to share your files to the container, I will suggest you mount the Azure File share to the container. But you need to pay attention to the caution here:
Linking an existing directory in a web app to a storage account will delete the directory contents.
So you need to mount the Azure File Share to a new directory without necessary files. And you can get more details about the steps in Configure Azure Files in a Container on App Service. It not only supports Windows containers but also supports Linux containers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With