Search code examples
dockerdockerfiledocker-for-windows

How to install ODBC Driver 17 in a docker image based on windows server core?


I'm setting up a new docker windows servercore image for my application. Data access uses ODBC Driver 17 for SQL Server. I need to install this on the image so in my Dockerfile I included the following:

FROM mcr.microsoft.com/windows/servercore:ltsc2016

COPY msodbcsql_17.3.1.1_x64.msi c:\\msodbcsql_17.3.1.1_x64.msi

RUN msiexec.exe /i C:\\msodbcsql_17.3.1.1_x64.msi /norestart /qn IACCEPTMSODBCSQLLICENSETERMS=YES
...

When I run docker build... I get the following error

The command 'cmd /S /C msiexec.exe /i C:\\msodbcsql_17.3.1.1_x64.msi /norestart /qn IACCEPTMSODBCSQLLICENSETERMS=YES' returned a non-zero code: 1603

Code 1603 indicates that a restart is required.

I'm not sure how an image can be restarted. How do I proceed ahead with this? Without the driver, I won't be able to get my application running.


Solution

  • So I ran the MSI manually in the container with logging enabled. It turns out that the failure was occurring due to missing VC++ redistributable.

    So, I updated the Dockerfile by adding a line to copy and install vc_redist.x64.exe which fixed the issue for me.

    Snippet from the Dockerfile that solved the problem for me.

    FROM mcr.microsoft.com/dotnet/framework/aspnet:4.7.2
    COPY vc_redist.x64.exe c:/ \
         msodbcsql_17.3.1.1_x64.msi c:/
    RUN c:\\vc_redist.x64.exe /install /passive /norestart 
    RUN msiexec.exe /i C:\\msodbcsql_17.3.1.1_x64.msi /norestart /qn /quiet /passive IACCEPTMSODBCSQLLICENSETERMS=YES 
    
    ...
    

    Just posting this answer here in case someone else stumbles upon the same issue.