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
Advertisement
Answer
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.