How to install msodbcsql in Debian-based Dockerfile with an Apple Silicon host?
Asked Answered
A

2

7

What I'm trying to do

Install Microsoft's ODBC driver into a Docker image using the following Dockerfile and the docker build command.:

FROM public.ecr.aws/docker/library/python:3.9.10-slim-buster

RUN apt-get update
RUN apt-get install -y curl gnupg
RUN curl -sSL https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl -sSL https://packages.microsoft.com/config/debian/10/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get update
RUN ACCEPT_EULA=Y apt-get install -y msodbcsql18

The majority of this Dockerfile is made up of commands from Microsoft's instructions on how to Install the Microsoft ODBC driver for SQL Server (Linux), specifically the Debian instructions.

What I expect to happen

Successful build of the Docker image.

What actually happens

  • docker build successfully builds the image if Docker is run on an Intel based MacBook Pro.
  • docker build returns the following error when Docker is run on an Apple Silicon M1 based MacBook Pro :
 => ERROR [7/7] RUN ACCEPT_EULA=Y apt-get install -y msodbcsql18                                                                                0.7s
------                                                                                                                                               
 > [7/7] RUN ACCEPT_EULA=Y apt-get install -y msodbcsql18:                                                                                           
#10 0.192 Reading package lists...
#10 0.541 Building dependency tree...
#10 0.610 Reading state information...
#10 0.661 E: Unable to locate package msodbcsql18
------
executor failed running [/bin/sh -c ACCEPT_EULA=Y apt-get install -y msodbcsql18]: exit code: 100

I have observed this issue side by side with multiple MacBook Pro's of different processor types before coming to the conclusion that this is an "Apple silicon issue." The results of my observation using different MacBooks are as follows:

 - MacBook Pro (14-inch, 2021) (M1)    (FAILS TO BUILD)
 - MacBook Pro (16-inch, 2021) (M1)    (FAILS TO BUILD)
 - MacBook Pro (13-inch, 2020) (Intel) (SUCCESSFUL BUILD)
 - MacBook Pro (16-inch, 2019) (Intel) (SUCCESSFUL BUILD) (2 different MacBooks tested)

Other details

I have confirmed that public.ecr.aws/docker/library/python:3.9.10-slim-buster is a Debian 10 based image by executing cat /etc/os-release in a basic container made from this image, resulting in:

PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

Conclusion

Given the blocker described above, how can I successfully install the Microsoft ODBC driver for SQL Server in a Docker image when Docker is installed on a MacBook Pro running on Apple's silicon?

Alanalana answered 9/3, 2022 at 18:50 Comment(0)
A
10

Why did this happen? This is a result of Microsoft lacking packages that support arm64 architecture (Apple silicon is ARM-based). Unbeknownst to me, this is apparently a detail that is observed at a lower level in Docker while requesting packages in the fashion described in the original question.

Solution The solution is to specify a supported platform architecture when building the image. This can be done as an argument to docker build, or it can be added between FROM and your image's identifier in your Dockerfile.

I experienced success using linux/amd64 as shown:

  • From the command line

    • docker build --platform=linux/amd64 .
  • In the Dockerfile

    • FROM --platform=linux/amd64 public.ecr.aws/docker/library/python:3.9.10-slim-buster
Alanalana answered 9/3, 2022 at 18:50 Comment(0)
B
3

In the latest docs we read

The Microsoft ODBC driver for SQL Server on macOS is only supported on the x64 architecture through version 17.7. Apple M1 (ARM64) support was added starting with version 17.8. The architecture will be detected and the correct package will be automatically installed by the Homebrew formula. If your command prompt is running in x64 emulation mode on the M1, the x64 package will be installed. If you're not running in emulation mode in your command prompt, the ARM64 package will be installed. Additionally, the Homebrew default directory changed with the M1, to /opt/homebrew. The paths below use the x64 Homebrew paths, which default to /usr/local, so your file paths will vary accordingly.

I'm also using python-slim-buster docker image, so Debian based, on ARM (M1 and M2) I managed to install msodbcsql with

RUN sh -c "curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -" \
    && apt-get update \
    && sh -c "curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list > /etc/apt/sources.list.d/mssql-release.list" \
    && apt-get update \
    && ACCEPT_EULA=Y apt-get install -y msodbcsql18 \
    && ACCEPT_EULA=Y apt-get install -y mssql-tools18

No idea why, but if you add debian config instead of ubuntu, it doesn't seem to work. Example that DOESN'T work but should

RUN sh -c "curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -" \
    && apt-get update \
    && sh -c "curl https://packages.microsoft.com/config/debian/`lsb_release -rs`/prod.list > /etc/apt/sources.list.d/mssql-release.list" \
    && apt-get update \
    && ACCEPT_EULA=Y apt-get install -y msodbcsql18 \
    && ACCEPT_EULA=Y apt-get install -y mssql-tools18
Buss answered 22/2, 2023 at 9:48 Comment(1)
[Debian11 on ARM] As for now, second one works properly.Sporangium

© 2022 - 2024 — McMap. All rights reserved.