0

I want to install MSSQL Server in a Python docker container to be able to run unit tests in a CI pipeline.

The problem is that the installation keeps failing. How can I fix it?

What I've tried

FROM python:3.7.9-slim-buster
RUN apt-get update

RUN apt-get -y install gnupg curl software-properties-common wget
RUN add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/18.04/mssql-server-2019.list)"
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
    && apt-get update \
    && ACCEPT_EULA=Y DEBIAN_FRONTEND=noninteractive apt-get install -y \
    unixodbc-dev \
    mssql-server
ENV MSSQL_PID 'developer'
ENV MSSQL_SA_PASSWORD 'Devel0per'
RUN /opt/mssql/bin/mssql-conf -n setup accept-eula
ENV SQLALCHEMY_DATABASE_URI mssql+pyodbc://dev_user:Devel0per@localhost:5432/dev_db

This gives:

Step 8/9 : RUN /opt/mssql/bin/mssql-conf -n setup accept-eula
 ---> Running in f3cebdb5b946
Traceback (most recent call last):
  File "/opt/mssql/bin/../lib/mssql-conf/mssql-conf.py", line 361, in <module>
    main()
  File "/opt/mssql/bin/../lib/mssql-conf/mssql-conf.py", line 357, in main
    processCommands()
  File "/opt/mssql/bin/../lib/mssql-conf/mssql-conf.py", line 262, in processCommands
    COMMAND_TABLE[args.which]()
  File "/opt/mssql/bin/../lib/mssql-conf/mssql-conf.py", line 58, in handleSetup
    exit(mssqlconfhelper.setupSqlServer(True, noprompt=args.noprompt))
  File "/opt/mssql/lib/mssql-conf/mssqlconfhelper.py", line 971, in setupSqlServer
    if not checkInstall():
  File "/opt/mssql/lib/mssql-conf/mssqlconfhelper.py", line 941, in checkInstall
    return runScript(checkInstallScript, True) == 0
  File "/opt/mssql/lib/mssql-conf/mssqlconfhelper.py", line 930, in runScript
    return subprocess.call([sudo, "-EH", pathToScript])
  File "/usr/lib/python2.7/subprocess.py", line 172, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib/python2.7/subprocess.py", line 394, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1047, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

Try 2

FROM mcr.microsoft.com/mssql/server:2019-latest
RUN apt-get update

gives

Step 2/2 : RUN apt-get update
 ---> Running in a1f0ef2cdd3f
Reading package lists...
E: List directory /var/lib/apt/lists/partial is missing. - Acquire (13: Permission denied)
The command '/bin/sh -c apt-get update' returned a non-zero code: 100
3
  • Given all of the MS examples use MSSQL_PID='Developer' with a capital D, have you tried using Developer with a capital D? Commented Sep 24, 2020 at 12:48
  • I suspect the SQL Server Developer image already contains Python - after all, Python integration is a major ML feature. Instead of trying to add SQL Server to a Python image why not try to add missing packages to a SQL Server image? Commented Sep 24, 2020 at 13:02
  • " why not try to add missing packages to a SQL Server image" - I did, see above. the mcr.microsoft.com/mssql/server:2019-latest actually contains Python, but Python 2.7 Commented Sep 24, 2020 at 13:25

1 Answer 1

1

The second example should be:

FROM mcr.microsoft.com/mssql/server:2019-latest
USER root
RUN apt-get update && \
    # install python

USER mssql

Microsoft doesn't document it anywhere, but this image contains two users and sets the unpriviledged user mssql as the default one.

Sign up to request clarification or add additional context in comments.

2 Comments

fwiw you can find this information when inspecting the image(s): docker inspect mcr.microsoft.com/mssql/server:2019-latest --format {{.Config.User}} or running a container i.e.: docker run --rm -i --entrypoint id mcr.microsoft.com/mssql/server:2019-latest
Or you can do what I usually do and inspect the image's layers with something like Dive or Portainer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.