简体   繁体   中英

Install unixodbc-dev for a Flask web app on Azure App Service

I am trying to deploy Flask web app on the Azure App Service. This app is using pyodbc to connect to mssql; however, when I deploy the app I get this error

ImportError: libodbc.so.2: cannot open shared object file: No such file or directory

I got to know that I can solve this issue by installing unixodbc/unixodbc-dev with the following line:

sudo apt-get install unixodbc-dev

I tried to do this manually by accessing the SSH of Kudu; however, the issue still persists.

I am using a local repository and pushing the code with git to Azure. When I get this error, I can't access the console from Kudu, so I had to comment the code and push again. Then I tried to install this package manually by doing apt-get install unixodbc-dev (because sudo is not recognized) and it works well. Then I pushed the code again with pyodbc on it and the same error is showing. I think the packages are being erased each time I do that since I found some of the folders created by this packages being deleted after the push action.

The error I always get is as follow:

日志流中的行

According to your description, you were using Azure WebApp for Linux which be based on Docker. So any changes you did in a container just be writen in the container layer which will be deleted when a contaner is deleted (includes stop/restart operation), as the offical Docker document About images, containers, and storage drivers said as below.

Images and layers

When you create a new container, you add a new writable layer on top of the underlying layers. This layer is often called the "container layer" . All changes made to the running container, such as writing new files, modifying existing files, and deleting files, are written to this thin writable container layer.

Container and layers

The major difference between a container and an image is the top writable layer. All writes to the container that add new or modify existing data are stored in this writable layer. When the container is deleted, the writable layer is also deleted. The underlying image remains unchanged.

Therefore, if you want to save your changes in your running container, you must to commit these changes to create a new image via command docker commit . Or in your scenario for installing the required packages, you can follow the Azure documents SSH support for Azure App Service on Linux and Use a custom Docker image for Web App for Containers to add these commands as below into your Dockerfile to create a image to push and deploy it to Azure WebApp for Linux.

# Add unixodbc support
RUN apt-get update \
        && apt-get install -y --no-install-recommends unixodbc-dev

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM