1

I have Jenkins installed locally on my laptop running windows 10. I spin up a Linux container running SQL Server, however when I attempt to run the following:

 winpty docker exec -it SQLLinuxnull sudo /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P P@ssword1 -Q 'EXEC sp_configure '\''clr enabled'\'', 1;'

I get:

stdin is not a tty

When I run the docker exec command from a powershell session it completes without any issues. Trawling this site pulls up answer suggesting that this might be something to do with whatever account is being used in the Linux container requiring the ability to execute sudo and that I should alter the /etc/sudoers file, the problem being is that I do not have an /etc/sudoers file, according to uname -a this is the version of Linux the container is based on (not that its base is the official Microsoft SQL server in Linux image):

# uname -a
Linux f9509a952eae 4.9.49-moby #1 SMP Wed Sep 27 00:36:29 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

Can someone confirm that this is a sudoers related issue.

Matt
  • 68,711
  • 7
  • 155
  • 158
ChrisAdkin
  • 1,236
  • 1
  • 16
  • 31
  • I believe `docker -it` expects a TTY, so no, this *isn't* necessarily a sudoers issue. Though you should be able to stop using the `-it` arguments to `docker` (assuming that the `sudo` invocation is passwordless) if you configured your `sudoers` to not have the `RequireTTY` flag set. – Charles Duffy Nov 07 '17 at 02:27
  • (That said, if you didn't have a `/etc/sudoers` visible from the relevant namespace then `sudo` wouldn't work, so that's obviously incorrect. That said, the Linux kernel version has *nothing whatsoever* to do with the userspace tools, so the provided kernel release tells us nothing about the `sudo` installation). – Charles Duffy Nov 07 '17 at 02:28
  • (...note "visible from the relevant namespace" -- ie. we care about whether there's an `/etc/sudoers` *inside the Docker container*, not inside the Linux install that's hosting Docker). – Charles Duffy Nov 07 '17 at 02:31
  • Do you need `sudo` for that command? It's the `requiretty` option in the sudo config – Matt Nov 07 '17 at 02:32
  • @Matt, ...however, if `sudo` were failing because RequireTTY isn't set, that's a different message. So I'm pretty sure `docker` is failing before it gets to invoking `sudo`. – Charles Duffy Nov 07 '17 at 02:32
  • @CharlesDuffy Ah ok, but if not sudo it could be shell initialisation either before or after sudo. `docker exec` has run and moved into the Linux VM space for a `stdin is not a tty` message to appear. The command might even work without the `-it` as then there won't be a psuedo tty for whatever is trying to use it. – Matt Nov 07 '17 at 02:43
  • I have no idea what `winpty` adds into the mix though – Matt Nov 07 '17 at 02:47
  • @CharlesDuffy removing the -it did the trick, if you reply to the thread I will mark your response as the answer and upvote it. – ChrisAdkin Nov 07 '17 at 09:40
  • 1
    Possible duplicates: https://stackoverflow.com/q/43099116/596285 and https://stackoverflow.com/q/40536778/596285 – BMitch Nov 07 '17 at 14:36

1 Answers1

3
docker exec -it

...requires that it be run in a context with a TTY available. If you can avoid needing stdin or a terminal later in the program's execution (for example, having /etc/sudoers inside the container configured with the RequireTTY option disabled), you should be able to simply remove the -it flags.

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441