Search code examples
linuxdockerdockerfilearmodbc

Microsoft ODBC Driver 18 for Python Docker Image, ARM Device; Build Error


Trying to build a docker for a Python (Django) application, which requires Microsoft ODBC 18, which I am using the following docker file below:

FROM python:latest

RUN apt update
RUN apt-get install -y gcc libc-dev g++ libffi-dev libxml2 unixodbc-dev unixodbc

RUN curl https://packages.microsoft.com/keys/microsoft.asc | tee /etc/apt/trusted.gpg.d/microsoft.asc \
    && curl https://packages.microsoft.com/config/debian/12/prod.list | tee /etc/apt/sources.list.d/mssql-release.list \
    && apt-get update \
    && ACCEPT_EULA=Y apt-get install -y msodbcsql18 \
    && echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc

RUN odbcinst -j

WORKDIR /app

COPY django-requirements.txt /app/
RUN pip install --no-cache-dir -r django-requirements.txt

COPY . /app/

CMD ["bash"]

Some portions of the commands are referenced off from https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server

Docker Error Log:

Sending build context to Docker daemon  635.9kB
Step 1/10 : FROM python:latest
 ---> d8be44680b2e
Step 2/10 : RUN apt update
 ---> Using cache
 ---> 462376801705
Step 3/10 : RUN apt-get install -y gcc libc-dev g++ libffi-dev libxml2 unixodbc-dev unixodbc
 ---> Using cache
 ---> 4804e4898355
Step 4/10 : RUN curl https://packages.microsoft.com/keys/microsoft.asc | tee /etc/apt/trusted.gpg.d/microsoft.asc     && curl https://packages.microsoft.com/config/debian/12/prod.list | tee /etc/apt/sources.list.d/mssql-release.list     && apt-get update     && ACCEPT_EULA=Y apt-get install -y msodbcsql18     && echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc
 ---> Running in e2adb15edb3e
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   983  100   983    0     0  16821      0 --:--:-- --:--:-- --:--:-- 16948
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.7 (GNU/Linux)

mQENBFYxWIwBCADAKoZhZlJxGNGWzqV+1OG1xiQeoowKhssGAKvd+buXCGISZJwT
LXZqIcIiLP7pqdcZWtE9bSc7yBY2MalDp9Liu0KekywQ6VVX1T72NPf5Ev6x6DLV
7aVWsCzUAF+eb7DC9fPuFLEdxmOEYoPjzrQ7cCnSV4JQxAqhU4T6OjbvRazGl3ag
OeizPXmRljMtUUttHQZnRhtlzkmwIrUivbfFPD+fEoHJ1+uIdfOzZX8/oKHKLe2j
H632kvsNzJFlROVvGLYAk2WRcLu+RjjggixhwiB+Mu/A8Tf4V6b+YppS44q8EvVr
M+QvY7LNSOffSO6Slsy9oisGTdfE39nC7pVRABEBAAG0N01pY3Jvc29mdCAoUmVs
ZWFzZSBzaWduaW5nKSA8Z3Bnc2VjdXJpdHlAbWljcm9zb2Z0LmNvbT6JATUEEwEC
AB8FAlYxWIwCGwMGCwkIBwMCBBUCCAMDFgIBAh4BAheAAAoJEOs+lK2+EinPGpsH
/32vKy29Hg51H9dfFJMx0/a/F+5vKeCeVqimvyTM04C+XENNuSbYZ3eRPHGHFLqe
MNGxsfb7C7ZxEeW7J/vSzRgHxm7ZvESisUYRFq2sgkJ+HFERNrqfci45bdhmrUsy
7SWw9ybxdFOkuQoyKD3tBmiGfONQMlBaOMWdAsic965rvJsd5zYaZZFI1UwTkFXV
KJt3bp3Ngn1vEYXwijGTa+FXz6GLHueJwF0I7ug34DgUkAFvAs8Hacr2DRYxL5RJ
XdNgj4Jd2/g6T9InmWT0hASljur+dJnzNiNCkbn9KbX7J/qK1IbR8y560yRmFsU+
NdCFTW7wY0Fb1fWJ+/KTsC4=
=J6gs
-----END PGP PUBLIC KEY BLOCK-----
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   138  100   138    0     0   1403      0 --:--:-- --:--:-- --:--:--  1408
deb [arch=amd64,arm64,armhf signed-by=/usr/share/keyrings/microsoft-prod.gpg] https://packages.microsoft.com/debian/12/prod bookworm main
Hit:1 http://deb.debian.org/debian bookworm InRelease
Get:2 http://deb.debian.org/debian bookworm-updates InRelease [52.1 kB]
Get:3 http://deb.debian.org/debian-security bookworm-security InRelease [48.0 kB]
Get:4 https://packages.microsoft.com/debian/12/prod bookworm InRelease [3617 B]
Err:4 https://packages.microsoft.com/debian/12/prod bookworm InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY EB3E94ADBE1229CF
Reading package lists...
W: GPG error: https://packages.microsoft.com/debian/12/prod bookworm InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY EB3E94ADBE1229CF
E: The repository 'https://packages.microsoft.com/debian/12/prod bookworm InRelease' is not signed.
The command '/bin/sh -c curl https://packages.microsoft.com/keys/microsoft.asc | tee /etc/apt/trusted.gpg.d/microsoft.asc     && curl https://packages.microsoft.com/config/debian/12/prod.list | tee /etc/apt/sources.list.d/mssql-release.list     && apt-get update     && ACCEPT_EULA=Y apt-get install -y msodbcsql18     && echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc' returned a non-zero code: 100
ERROR: Service 'backend' failed to build : Build failed

More Context

This docker is running on an ARM system, specifically Raspberry Pi 5 (8GB Ram) using Raspberry Pi OS.
To support ODBC Driver for ARM I referenced off this GitHub issue, which states that version 18 is supported by ARM, but not 17.

Attempted Solution 1

RUN curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg \
    && mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg \
    && curl https://packages.microsoft.com/config/debian/12/prod.list > /etc/apt/sources.list.d/mssql-release.list \
    && apt-get update \
    && ACCEPT_EULA=Y apt-get install -y msodbcsql18 \
     && echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc

Returns a nearly identical error log

Attempted Solution 2

RUN curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg \
    && mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg \
    && curl https://packages.microsoft.com/config/debian/12/prod.list > /etc/apt/sources.list.d/mssql-release.list \
    && apt-get update --allow-insecure-repositories \
    && apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EB3E94ADBE1229CF \
    && ACCEPT_EULA=Y apt-get install -y msodbcsql18 \
    && echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc

Solution 2 Error Log

Building backend
Sending build context to Docker daemon  635.9kB
Step 1/10 : FROM python:latest
 ---> d8be44680b2e
Step 2/10 : RUN apt update
 ---> Using cache
 ---> 462376801705
Step 3/10 : RUN apt-get install -y gcc libc-dev g++ libffi-dev libxml2 unixodbc-dev unixodbc
 ---> Using cache
 ---> 4804e4898355
Step 4/10 : RUN curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg     && mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg     && curl https://packages.microsoft.com/config/debian/12/prod.list > /etc/apt/sources.list.d/mssql-release.list     && apt-get update --allow-insecure-repositories     && apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EB3E94ADBE1229CF     && ACCEPT_EULA=Y apt-get install -y msodbcsql18     && echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc
 ---> Running in 8bff72a76121
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   983  100   983    0     0  16094      0 --:--:-- --:--:-- --:--:-- 16383
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   138  100   138    0     0   1317      0 --:--:-- --:--:-- --:--:--  1326
Hit:1 http://deb.debian.org/debian bookworm InRelease
Get:2 http://deb.debian.org/debian bookworm-updates InRelease [52.1 kB]
Get:3 http://deb.debian.org/debian-security bookworm-security InRelease [48.0 kB]
Get:4 https://packages.microsoft.com/debian/12/prod bookworm InRelease [3617 B]
Ign:4 https://packages.microsoft.com/debian/12/prod bookworm InRelease
Get:5 https://packages.microsoft.com/debian/12/prod bookworm/main amd64 Packages [29.0 kB]
Get:6 https://packages.microsoft.com/debian/12/prod bookworm/main all Packages [342 B]
Get:7 https://packages.microsoft.com/debian/12/prod bookworm/main armhf Packages [5287 B]
Get:8 https://packages.microsoft.com/debian/12/prod bookworm/main arm64 Packages [5812 B]
Fetched 144 kB in 0s (377 kB/s)
Reading package lists...
W: GPG error: https://packages.microsoft.com/debian/12/prod bookworm InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY EB3E94ADBE1229CF
W: The repository 'https://packages.microsoft.com/debian/12/prod bookworm InRelease' is not signed.
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
Executing: /tmp/apt-key-gpghome.T3Z92aFNHv/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys EB3E94ADBE1229CF
gpg: key EB3E94ADBE1229CF: "Microsoft (Release signing) <[email protected]>" not changed
gpg: Total number processed: 1
gpg:              unchanged: 1
Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
  odbcinst
The following NEW packages will be installed:
  msodbcsql18 odbcinst
0 upgraded, 2 newly installed, 0 to remove and 2 not upgraded.
Need to get 703 kB of archives.
After this operation, 87.0 kB of additional disk space will be used.
WARNING: The following packages cannot be authenticated!
  msodbcsql18
E: There were unauthenticated packages and -y was used without --allow-unauthenticated
The command '/bin/sh -c curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg     && mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg     && curl https://packages.microsoft.com/config/debian/12/prod.list > /etc/apt/sources.list.d/mssql-release.list     && apt-get update --allow-insecure-repositories     && apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EB3E94ADBE1229CF     && ACCEPT_EULA=Y apt-get install -y msodbcsql18     && echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc' returned a non-zero code: 100
ERROR: Service 'backend' failed to build : Build failed

Solution

  • This error is due to missing microsoft key at /usr/share/keyrings/microsoft-prod.gpg, you have two options,

    Option 1: Remove signed-by value (Recommended)

    This approach is suggested in Microsoft notes,

    The original content in https://packages.microsoft.com/config/debian/12/prod.list is as,

    deb [arch=amd64,arm64,armhf signed-by=/usr/share/keyrings/microsoft-prod.gpg] https://packages.microsoft.com/debian/12/prod bookworm main
    

    after removing signed-by,

    deb [arch=amd64,arm64,armhf] https://packages.microsoft.com/debian/12/prod bookworm main
    

    So, your docker file will look like,

    FROM python:latest
    
    RUN apt update
    RUN apt-get install -y gcc libc-dev g++ libffi-dev libxml2 unixodbc-dev unixodbc
    
    RUN curl https://packages.microsoft.com/keys/microsoft.asc | tee /etc/apt/trusted.gpg.d/microsoft.asc \
        && echo "deb [arch=amd64,arm64,armhf] https://packages.microsoft.com/debian/12/prod bookworm main" | tee /etc/apt/sources.list.d/mssql-release.list \
        && apt-get update \
        && ACCEPT_EULA=Y apt-get install -y msodbcsql18 \
        && echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc
    
    RUN odbcinst -j
    
    WORKDIR /app
    
    COPY django-requirements.txt /app/
    RUN pip install --no-cache-dir -r django-requirements.txt
    
    COPY . /app/
    
    CMD ["bash"]
    

    Option 2: Add microsoft key

    Add your microsoft keyring files by following command,

    curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | sudo gpg --dearmor -o /usr/share/keyrings/microsoft-prod.gpg
    

    See here for more info.