0

I am working on a SQL Server 2017 Docker container. The database will never start.

I have customized the image only to run the health check. Same problem occurs without using the cusotmized Dockerfile.

The host machine has ipv6 completely disabled. Docker's daemon.json has property "ipv6" : false.

Dockerfile (out of date)

FROM mcr.microsoft.com/mssql/server:2017-latest-ubuntu

ENV ACCEPT_EULA=Y

EXPOSE 1433
HEALTHCHECK --interval=10s --timeout=3s --start-period=10s --retries=10 \
    CMD /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P ${SA_PASSWORD} -Q "SELECT 1" || exit 1

Log

2019-12-03 15:10:44.73 spid19s     SQL Server could not spawn FRunCommunicationsManager thread. Check the SQL Server error log and the operating system error log for information about possible related problems.
2019-12-03 15:10:44.71 spid19s     Server failed to listen on 'any' <ipv6> 1433. Error: 0x2742. To proceed, notify your system administrator.
2019-12-03 15:10:44.71 spid19s     TDSSNIClient initialization failed with error 0x2742, status code 0xa. Reason: Unable to initialize the TCP/IP listener. A socket operation encountered a dead network. 
2019-12-03 15:10:44.72 spid19s     TDSSNIClient initialization failed with error 0x2742, status code 0x1. Reason: Initialization failed with an infrastructure error. Check for previous errors. A socket operation encountered a dead network. 
2019-12-03 15:10:44.71 spid19s     Error: 26024, Severity: 16, State: 1.
2019-12-03 15:10:44.71 spid19s     Error: 17182, Severity: 16, State: 1.
2019-12-03 15:10:44.72 spid19s     Error: 17182, Severity: 16, State: 1.
2019-12-03 15:10:44.72 spid19s     Error: 17826, Severity: 18, State: 3.
2019-12-03 15:10:44.72 spid19s     Could not start the network library because of an internal error in the network library. To determine the cause, review the errors immediately preceding this one in the error log.
2019-12-03 15:10:44.73 spid19s     Error: 17120, Severity: 16, State: 1.

I have tried to run sysctl on the container directly to explicitly disable ipv6, but seems not required.

$ sysctl -w net.ipv6.conf.all.disable_ipv6=1
sysctl: cannot stat /proc/sys/net/ipv6/conf/all/disable_ipv6: No such file or directory

Question: how do I fix this? Is the problem really related to ipv6 disconnectivity? Any way to tell mssql not to ever try to use ipv6?

Update

I have tried the following Dockerfile

FROM mcr.microsoft.com/mssql/server:2017-latest-ubuntu

ENV MSSQL_IP_ADDRESS=0.0.0.0
ENV ACCEPT_EULA=Y
ENV MSSQL_PID=Express
RUN MSSQL_IP_ADDRESS=0.0.0.0 /opt/mssql/bin/mssql-conf setup
EXPOSE 1433
HEALTHCHECK --interval=10s --timeout=3s --start-period=10s --retries=10 \
    CMD /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P ${SA_PASSWORD} -Q "SELECT 1" || exit 1

Error is

Building image...
Preparing build context archive...
[==================================================>]2/2 files
Done

Sending build context to Docker daemon...
[==================================================>]  566,0B
Done

Step 1/7 : FROM mcr.microsoft.com/mssql/server:2017-latest-ubuntu
 ---> cfe5615bf6a8
Step 2/7 : ENV MSSQL_IP_ADDRESS=0.0.0.0
 ---> Running in d65d0c977ea1
Removing intermediate container d65d0c977ea1
 ---> 358ed84b0ae7
Step 3/7 : ENV ACCEPT_EULA=Y
 ---> Running in b0a6b46edb0a
Removing intermediate container b0a6b46edb0a
 ---> ed69c043b383
Step 4/7 : ENV MSSQL_PID=Express
 ---> Running in e58a9930791c
Removing intermediate container e58a9930791c
 ---> 94f055e34ba0
Step 5/7 : RUN MSSQL_IP_ADDRESS=0.0.0.0 /opt/mssql/bin/mssql-conf setup
 ---> Running in 508cacc5158a
Traceback (most recent call last):
  File "/opt/mssql/bin/../lib/mssql-conf/mssql-conf.py", line 279, in <module>
    main()
  File "/opt/mssql/bin/../lib/mssql-conf/mssql-conf.py", line 275, in main
    processCommands()
  File "/opt/mssql/bin/../lib/mssql-conf/mssql-conf.py", line 199, in processCommands
    COMMAND_TABLE[args.which]()
  File "/opt/mssql/bin/../lib/mssql-conf/mssql-conf.py", line 54, in handleSetup
    exit(mssqlconfhelper.setupSqlServer(eulaAccepted, noprompt=args.noprompt))
  File "/opt/mssql/lib/mssql-conf/mssqlconfhelper.py", line 795, in setupSqlServer
    if not checkInstall():
  File "/opt/mssql/lib/mssql-conf/mssqlconfhelper.py", line 765, in checkInstall
    return runScript(checkInstallScript, True) == 0
  File "/opt/mssql/lib/mssql-conf/mssqlconfhelper.py", line 754, in runScript
    return subprocess.call([sudo, "-EH", pathToScript])
  File "/usr/lib/python2.7/subprocess.py", line 523, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1343, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory
Error response from daemon: The command '/bin/sh -c MSSQL_IP_ADDRESS=0.0.0.0 /opt/mssql/bin/mssql-conf setup' returned a non-zero code: 1
Community
  • 1
  • 1
usr-local-ΕΨΗΕΛΩΝ
  • 26,101
  • 30
  • 154
  • 305

1 Answers1

1

This appears to be a documented issue, that you'll find with a search of the error:

Server failed to listen on 'any' <ipv6> 1433. Error: 0x2742

This leads you to the documentation: Mssql-conf tool fails if IPV6 is disabled on the Linux system which describes the problem:

Symptoms

Assume that you try to install Microsoft SQL Server 2017 on a Linux operating system such as Redhat or Ubuntu. If IPv6 is disabled at the OS kernel level, and you try to configure SQL Server by using the "sudo /opt/mssql/bin/mssql-conf setup" command, you receive the following messages in the Linux console and SQL Server error log. Additionally, the configuration may fail.

And we can see the errors you describe in the above mentioned error log:

SQL Server error log:

 ...
 DateTimeAndSpid     Error: 26024, Severity: 16, State: 1.​
 DateTimeAndSpid     Server failed to listen on 'any' <ipv6> 1433. Error: 0x2742. To proceed, notify your system administrator.​
 DateTimeAndSpid     Error: 17182, Severity: 16, State: 1.​
 DateTimeAndSpid     TDSSNIClient initialization failed with error 0x2742, status code 0xa. Reason: Unable to initialize the TCP/IP listener. A socket operation encountered a dead network.​
 DateTimeAndSpid     Error: 17182, Severity: 16, State: 1.​
 DateTimeAndSpid     TDSSNIClient initialization failed with error 0x2742, status code 0x1. Reason: Initialization failed with an infrastructure error. Check for previous errors. A socket operation encountered a dead network.​
 ...

And offers a workaround:

Workaround

To work around the issue, run the following command:

sudo MSSQL_IP_ADDRESS=0.0.0.0 /opt/mssql/bin/mssql-conf setup

Currently, it doesn't appear that Microsoft are working to "avoid" the error apart from by specifying the above workaround (this could be due to it being by "design"):

Status

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.

Thom A
  • 88,727
  • 11
  • 45
  • 75
  • I should be doing that in my Dockerfile perhaps. Thanks for the great help. I will try it – usr-local-ΕΨΗΕΛΩΝ Dec 03 '19 at 16:05
  • @usr-local-ΕΨΗΕΛΩΝ, you might setting the environment variable `MSSQL_IP_ADDRESS=0.0.0.0` in your dockerfile or on the run command. – Dan Guzman Dec 04 '19 at 03:10
  • @DanGuzman no, didn't work. I am not sure what `mssql-conf setup` does, but indeed it was executed in an earlier layer. When you set an ENV variable in Dockerfile it will be set only in the outermost layer. For example, MSSQL could have already hardcoded `::0` in some configuration somewhere, and needs to run that script again – usr-local-ΕΨΗΕΛΩΝ Dec 04 '19 at 08:32
  • And for the record `RUN MSSQL_IP_ADDRESS=0.0.0.0 /opt/mssql/bin/mssql-conf setup` did not work, build failed because of Python errors that can't be displayed in a *comment* – usr-local-ΕΨΗΕΛΩΝ Dec 04 '19 at 08:33
  • Python errors? SQL Server doesn't run in python. That doesn't sound like you ran the command correctly, @usr-local-ΕΨΗΕΛΩΝ . – Thom A Dec 04 '19 at 09:00
  • Opening a new (exact same) question would just get closed as a duplicate. I don't use docker (I use lxc) for containers, so I can't tell you how you'd run a command against a docker container with certainty, @usr-local-ΕΨΗΕΛΩΝ , but according to the [documentation](https://docs.docker.com/engine/reference/commandline/exec/) it would seem you want to run `docker exec -d YourContainer MSSQL_IP_ADDRESS=0.0.0.0 /opt/mssql/bin/mssql-conf setup`. – Thom A Dec 04 '19 at 09:11
  • My concern is that docker exec must be run against an active container. I am trying to build a reusable container for other developers. If I need to tell the guys "don't forget to run this customized command bla bla bla" it defeats the purpose of Dockerfiles – usr-local-ΕΨΗΕΛΩΝ Dec 04 '19 at 09:15
  • I see your point there. I'm afraid I don't have any knowledge of Docker. I can give you the SQL Server side of the answer, and why the instance isn't starting, but how you impement that into a docker file, I have no idea. – Thom A Dec 04 '19 at 09:18
  • You already helped a lot @Larnu don't worry. Someone else could continue from here... – usr-local-ΕΨΗΕΛΩΝ Dec 04 '19 at 09:31
  • @usr-local-ΕΨΗΕΛΩΝ, I successfully built and ran an image using the first (out of date) dockerfile in your question on both Windows and Ubuntu 16.04 with IPV6 disabled. The reason for the error in your second dockerfile is that `mssql-conf` isn't included in the final MS image. Note that one can configure SQL Server on docker with the MS image using [env variables](https://learn.microsoft.com/en-us/sql/linux/sql-server-linux-configure-environment-variables) rather than `mssql-conf`. What is your docker host OS? – Dan Guzman Dec 04 '19 at 12:10
  • @DanGuzman both Windows 10 and Centos 8. It makes sense that MS removed some packages after building the image – usr-local-ΕΨΗΕΛΩΝ Dec 04 '19 at 12:26
  • On Windows 10 (which has no IPv6 address but doesn't disable the stack) the plain image runs, on Centos it doesnt. The new dockerfile does not build on any platform because configuration packages are likely missing – usr-local-ΕΨΗΕΛΩΝ Dec 04 '19 at 12:32
  • ok, it all worked after also clearing the volume (which was empty anyway). Problem solved. Also note that if one has an exclamation mark in the "complex" SA password and passes it by command line, it will cause troubles because it is interpreted – usr-local-ΕΨΗΕΛΩΝ Dec 04 '19 at 12:35
  • @usr-local-ΕΨΗΕΛΩΝ, glad you got it sorted out. Adding that you can always build a custom image `FROM ubuntu:16.04` with instructions to install and /configure SQL Server if the out-of-the-box images don't fit your needs. – Dan Guzman Dec 04 '19 at 12:41
  • *"Also note that if one has an exclamation mark in the "complex" SA password and passes it by command line, it will cause troubles because it is interpreted"* I can't say I've experienced that problem in Ubuntu; and I have used accounts that contain several "special" characters (not alphanumerical). – Thom A Dec 04 '19 at 12:42