Installing MSSQL packages using a Dockerfile

I`m having a hard time installing the required packages for a Python/pyodbc app to run.

I’m trying to run it using the below code on a Dockerfile:

FROM python:3.9-slim-buster

RUN apt-get update
RUN apt-get clean

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

COPY main.py requirements.txt /app/
WORKDIR /app
RUN pip install -r requirements.txt

CMD ["python", "main.py"]

# Start the Flask app
CMD gunicorn app:app -b 0.0.0.0:80

But it’s throwing the following error:

error: failed to solve: process "/bin/sh -c curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -" did not complete successfully: exit code: 255

I tried several variations of this code, but none seem to work. What’s the correct way of installing MSSQL packages so I can run an app that uses pyodbc?

Hey,

It appears that cURL may not have been installed correctly in your image. To address this issue, you can try installing a few OS-level dependencies before running the cURL commands.

One possible solution is to follow the example set by this image, which includes the necessary dependencies for cURL to function properly.

FROM python:3.9-slim-busterRUN apt-get update && \ apt-get install -y --no-install-recommends \ build-essential \ unixodbc-dev \ curl \ gnupg2 && \ apt-get cleanRUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - && \ curl https://packages.microsoft.com/config/debian/10/prod.list > /etc/apt/sources.list.d/mssql-release.list && \ apt-get update && \ ACCEPT_EULA=Y apt-get install -y msodbcsql17 && \ apt-get clean

Regards.
Jérémy, Render Support

Hello, thanks for reaching out. I tried updating my code with the snippet you provided:

FROM python:3.9-slim-buster
RUN apt-get update && \ apt-get install -y --no-install-recommends \ build-essential \ unixodbc-dev \ curl \ gnupg2 && \ apt-get clean
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - && \ curl https://packages.microsoft.com/config/debian/10/prod.list > /etc/apt/sources.list.d/mssql-release.list && \ apt-get update && \ ACCEPT_EULA=Y apt-get install -y msodbcsql17 && \ apt-get clean

It now raises a different error:

error: failed to solve: process "/bin/sh -c apt-get update && \\ apt-get install -y --no-install-recommends \\ build-essential \\ unixodbc-dev \\ curl \\ gnupg2 && \\ apt-get clean" did not complete successfully: exit code: 127

Am I missing something?

Using \ is a way to improve readability in multiline commands. You should use it when continuing the command in a new line.

So your Dockerfile should be formatted like:

1 Like

Hey,

Make sure that all of the commands I gave you that end with a slash (/) are followed by a new line or don’t put slashes at all.

Regards.
Jérémy, Render Support

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.