Docker Community Forums

Share and learn in the Docker community.

Container unable to connect to SQL Server locally


(Jdeighan) #1

At home, I have both a desktop and a laptop, both running an up-to-date Windows 10 Pro, both connected to my Linksys router. On both I have the Docker for Windows beta installed. The laptop has an instance of Microsoft SQL Server running ('select @@version yields "Microsoft SQL Server 2008 R2 (SP1) - 10.50.2500.0 (X64) Jun 17 2011 00:54:03 Copyright © Microsoft Corporation Developer Edition (64-bit) on Windows NT 6.2 (Build 9200: ) (Hypervisor) ")

I can build a Docker container on the desktop that includes WinODBC and can successfully connect to the SQL Server running on the laptop, including returning results from a SQL query. ODBC is configured to connect to “DeighanSurface”, the Windows computer name of the laptop (a Microsoft Surface Pro 3). I am doing nothing special to open port 1433 for the container (but it’s open in the computer’s firewall).

However, if I build the same container from the same source code on the laptop (where SQL Server is installed and running), the container that I build there cannot connect to the SQL Server instance. Here is the output from trying to run a Perl test script (the same one that succeeds on the desktop) in a bash shell:

C:\SQLTest> docker run -it --rm sqltest
root@883ee8c80738:/home/user# perl dbtest.pl
DBI connect(‘LocalServer’,‘easyiep’,…) failed: [unixODBC][Microsoft][ODBC Driver 11 for SQL Server]Login timeout expired (SQL-HYT00) [state was HYT00 now 08001]
[unixODBC][Microsoft][ODBC Driver 11 for SQL Server]TCP Provider: Error code 0x2AF9 (SQL-08001)
[unixODBC][Microsoft][ODBC Driver 11 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. (SQL-08001) at dbtest.pl line 15.
Connection failed: at dbtest.pl line 15.
root@883ee8c80738:/home/user#

Expected behavior

The docker container should connect to the SQL Server running on the same computer.

Actual behavior

The connection fails with the error message above.

Information

  • the output of:
    • pinata diagnose -u on OSX
    • DockerDebugInfo.ps1 using Powershell on Windows
  • a reproducible case if this is a bug, Dockerfiles FTW
  • page URL if this is a docs issue or the name of a man page
  • host distribution and version ( OSX 10.10.x, OSX 10.11.x, Windows, etc )

In my PowerShell, DockerDebugInfo.ps1 just yields:

DockerDebugInfo.ps1: The term 'DockerDebugInfo.ps1’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1

  • DockerDebugInfo.ps1
  •   + CategoryInfo          : ObjectNotFound: (DockerDebugInfo.ps1`:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException
    
    

Steps to reproduce the behavior

You should provide a way to attach files to these bug reports. The setup is pretty simple, though. The file ODBC.ini contains:

[LocalServer]
Driver = ODBC Driver 11 for SQL Server
Server = DeighanSurface

The test script, dbtest.pl, contains:

#!/usr/bin/env perl

use strict;
use warnings;
use Data::Dumper;

use DBI;
use DBD::ODBC;

my $user = ‘easyiep’;
my $pwd = ‘ifahwtrg’;

---------------------------------------------------------------------------

MAIN: {
my $dbh = DBI->connect(“dbi:ODBC:LocalServer”, $user, $pwd)
|| die(“Connection failed: $!”);
my $lData = $dbh->selectall_arrayref(“select count(*) from PermissionTypes”);
my $count = $lData->[0]->[0];
print(“There are $count PermissionTypes - OK\n”);
$dbh->disconnect();
} # MAIN()

The Docker file is this (NOTE: I’m getting the message "Sorry, new users can only include 2 links in a post. Not sure what that means, but this Dockerfile includes 2 URLs which I’m going to modify to get the post in the system):

FROM ubuntu:trusty
MAINTAINER John Deighan jdeighan@pcgus.com
ENV REFRESHED_AT 2016-06-02

— Download URLs

ENV MS_ODBC_URL htps://download.microsoft.com/download/B/C/D/BCDD264C-7517-4B7D-8159-C99FC5535680/RedHat6/msodbcsql-11.0.2270.0.tar.gz
ENV FIX_SCRIPT Microsoft–SQL-Server–ODBC-Driver-1.0-for-Linux-Fixed-Install-Scripts
ENV FIX_SCRIPT_URL htps://github.com/Andrewpk/${FIX_SCRIPT}/archive/master.zip

RUN apt-get -qq update
&& apt-get -y install unzip make gcc libkrb5-3 libgssapi-krb5-2 expat
libexpat1-dev tidy libtidy-dev libxml2-dev libssl-dev
libgd2-xpm-dev curl vim
wget aptitude dos2unix

— Download ODBC install files & scripts

RUN cd /tmp && wget -O msodbcsql.tar.gz ${MS_ODBC_URL} && wget -O odbc-fixed.zip ${FIX_SCRIPT_URL}

— Unzip downloaded files

RUN cd /tmp && tar -xzf ./msodbcsql.tar.gz && unzip -o ./odbc-fixed.zip && cp ./${FIX_SCRIPT}-master/* ./msodbcsql-11.0.2270.0

— Run install scripts

RUN cd /tmp/msodbcsql-11.0.2270.0 && yes YES | ./build_dm.sh --accept-warning --libdir=/usr/lib/x86_64-linux-gnu && ./install.sh install --accept-license --force

RUN cpan App::cpanminus

RUN cpanm DBI
RUN cpanm DBD::ODBC
RUN cpanm DBD::SQLite
RUN cpanm Date::Calc
RUN cpanm Tie::IxHash
RUN cpanm IO::Stringy
RUN cpanm Image::Size
RUN cpanm Storable
RUN cpanm FreezeThaw
RUN cpanm Readonly
RUN cpanm PDF::Reuse

RUN cpanm Data::ICal Date::ICal JSON Perl::Critic HTML::TagFilter Number::Format Data::Buffer Math::Units Class::Loader File::Which
RUN cpanm Test::Script Probe::Perl Parse::Eyapp Carp::Assert Perl::Tidy Pod::Spell PPIx::Utilities PPIx::Regexp Email::Address MIME::Lite
RUN cpanm Math::Random File::Find::Rule Switch XML::Hash Test::Inline Number::Compare Math::BigInt

RUN cpanm Crypt::PasswdMD5 Crypt::DSA Crypt::CAST5_PP Crypt::Rijndael
RUN cpanm Net::LDAP Net::FTPSSL Net::SAML2 Authen::SASL IO::Socket::IP IO::Socket::INET6 Socket6 Captcha::reCAPTCHA
RUN cpanm Data::UUID Digest Digest::SHA1 Test::More XML::DOM Mail::Sender Statistics::Basic Statistics::Descriptive Statistics::Distributions Statistics::TTest

RUN cpanm GD GD::Graph GD::Text Authen::Captcha Authen::Radius XML::LibXML
RUN cpanm Alien::Tidyp HTML::Tidy Time::Date CAM::PDF Archive::Zip SOAP::Lite

RUN mkdir /home/user
WORKDIR /home/user

ADD odbc.ini /etc/odbc.ini
ADD dbtest.pl /home/user

RUN dos2unix -k -q /etc/odbc.ini /home/user/dbtest.pl

ENV PERL5LIB /var/www/easyiep/PerlLibs
USER root

— Set the locale

RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

CMD /bin/bash


(Boikot) #2

Same issue here , the same configuration works on the host , but i m not able to connect inside the container in bridget or default networks


(Stephendrew) #3

Did either of you get to the bottom of this?


(Ptejalinux) #4

+1
Did anyone get through this error?