9

I have the below ubuntu docker file to which I want to add SQL Server ODBC Driver 17 for installation. When I build the docker file, I am getting an error: '/bin/sh -c apt-get install msodbcsql17' returned a non-zero code: 1

Could you please help?

I am referring to the article - https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver15

I followed the steps in the article in my Ubuntu VM and it works fine and I am able to run my python programs. However, when I use the docker file I get the error

FROM ubuntu:18.04

RUN apt update -y  &&  apt upgrade -y && apt-get update 
RUN apt install -y curl python3.7 git python3-pip openjdk-8-jdk unixodbc-dev

RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN exit
#RUN ACCEPT_EULA=Y apt-get install msodbcsql17
RUN apt-get update
RUN ACCEPT_EULA=Y  
RUN apt-get install msodbcsql17
#RUN ACCEPT_EULA=Y apt install msodbcsql17
RUN ACCEPT_EULA=Y apt install mssql-tools
RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc

COPY startup.sh /
RUN chmod +x /startup.sh
ENTRYPOINT ["sh","/startup.sh"]
Suraj
  • 575
  • 1
  • 9
  • 23
  • Rry: `RUN DEBIAN_FRONTEND=noninteractive ACCEPT_EULA=Y apt-get install -y mssql-tools unixodbc-dev \ && echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile \ && echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc` – Dan Guzman Feb 07 '20 at 01:48
  • Thanks for the details, but this does not work. I get the error - Unable to locate mssql-tools. I tried using msodbcsql17, i get the same error as well. – Suraj Feb 07 '20 at 03:23
  • Did you manage to get a fix for this @Suraj ? – Ed Baker Feb 14 '20 at 03:29
  • @EdBaker Apologies for the late reply. Yes I could get a fix. I have shared the details below – Suraj Feb 19 '20 at 03:30
  • No worries @Suraj - I got it going on debian 10, I had to change the TLS version to 1.0 in openssl, that worked. – Ed Baker Feb 19 '20 at 03:32

4 Answers4

14

I could get it working. Below is the updated Docker file snippet

FROM ubuntu:18.04

RUN apt update -y  &&  apt upgrade -y && apt-get update 
RUN apt install -y curl python3.7 git python3-pip openjdk-8-jdk unixodbc-dev

# Add SQL Server ODBC Driver 17 for Ubuntu 18.04
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get update
RUN ACCEPT_EULA=Y apt-get install -y --allow-unauthenticated msodbcsql17
RUN ACCEPT_EULA=Y apt-get install -y --allow-unauthenticated mssql-tools
RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc

COPY startup.sh /
RUN chmod +x /startup.sh
ENTRYPOINT ["sh","/startup.sh"]
Suraj
  • 575
  • 1
  • 9
  • 23
  • I'd like to point out that you are using both `apt` and `apt-get` in your code. Those are the same (after Ubuntu 16.04 / Debian 8 since `apt` exists). You just repeat the same thing with `apt update... apt-get update`. [APT vs APT-GET: What is the Difference?](https://phoenixnap.com/kb/apt-vs-apt-get#:~:text=APT%20Combines%20APT%2DGET%20and%20APT%2DCACHE%20Functionalities,-Prior%20to%20Ubuntu&text=With%20the%20release%20of%20Ubuntu,command%2Dline%20interface%20%E2%80%93%20apt.&text=Note%3A%20The%20apt%20command%20is,%2Dget%20and%20apt%2Dcache.) – Gergely M Mar 19 '21 at 21:20
1

If you are on WSL2 this error might be due to a clock issue not being correct.
open wsl2 and run

sudo hwclock --hctosys

refclock: https://www.thegeekstuff.com/2013/08/hwclock-examples/
wsl2 issue: https://github.com/microsoft/WSL/issues/5324

this might fix the issue with apt-get when using WSL2 backed docker for windows

Jim S
  • 11
  • 1
1

As addition to Suraj

His answer works on a Macbook M1 if you replace the first statement with:

FROM --platform=linux/amd64 ubuntu:18.04
Chiel
  • 1,865
  • 1
  • 11
  • 24
0

Mine worked with

RUN apt-get install -y unixodbc-dev && apt-get update && apt-get upgrade \
    && wget http://archive.ubuntu.com/ubuntu/pool/main/g/glibc/multiarch-support_2.27-3ubuntu1_amd64.deb \
    && apt-get install ./multiarch-support_2.27-3ubuntu1_amd64.deb \
    && apt-get update \
    && curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
    && curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list > /etc/apt/sources.list.d/mssql-release.list \ 
    && apt-get update \
    && ACCEPT_EULA=Y apt-get install -y --allow-unauthenticated msodbcsql17 \
    && apt-get update \
    && ACCEPT_EULA=Y apt-get install -y --allow-unauthenticated mssql-tools \
    && apt-get upgrade
Mauricio Maroto
  • 119
  • 1
  • 2
  • 11