Unable to connect to SQL Server using sqlcmd from inside Docker

Working with debian linux inside docker contaier. I have sqlcmd working properly and neseccary drivers are installed and localizable. I know the server exists:

root@0feafecac36f:/home/shiny# nmap -p 31010 -sT xxx.xxx.xxx.xxx Starting Nmap 7.60 ( https://nmap.org ) at 2018-01-25 20:46 UTC Nmap scan report for nile-h.tmthk.org (xxx.xxx.xxx.xxx) Host is up (0.019s latency). PORT STATE SERVICE 31010/tcp filtered unknown Nmap done: 1 IP address (1 host up) scanned in 0.59 seconds 

But, for the life of me, I cannot figure out how to connect using sqlcmd, and I'm not sure what tricks I have at my disposal to help. This command produces an error:

 sqlcmd -S nile-h.tmthk.org,31010 -U "*********" -P "********" Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Login timeout expired. Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : TCP Provider: Error code 0x2749. Sqlcmd: Error: Microsoft ODBC Driver 13 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.. 

I have verified the username and password. So what is going on here? Any ideas? I tried many iterations of sqlcmd to try and fix this, but so far nothing is working.

EDIT: Telnet

 root@0feafecac36f:/home/shiny# telnet xxx.xxx.xxx.xxx 31010 Trying xxx.xxx.xxx.xxx... telnet: Unable to connect to remote host: Connection refused 

EDIT: tcptraceroute

 root@0feafecac36f:/home/shiny# tcptraceroute xxx.xxx.xxx.xxx 31010 Selected device eth0, address 172.17.0.2, port 33859 for outgoing packets Tracing the path to xxx.xxx.xxx.xxx on TCP port 31010, 30 hops max 1 172.17.0.1 0.241 ms 0.179 ms 0.156 ms 2 nile-h.tmthk.org (xxx.xxx.xxx.xxx) [closed] 1012.571 ms 1003.511 ms 1003.485 ms 

EDIT: ip route get

 root@0feafecac36f:/home/shiny# ip route get xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx via 172.17.0.1 dev eth0 src 172.17.0.2 cache 

EDIT: Dockerfile

 FROM r-base:3.4.0 RUN apt-get update && apt-get install -y \ apt-utils \ curl \ libcurl4-openssl-dev \ libssl-dev \ r-cran-rjava \ gnupg2 \ r-cran-rodbc \ unixodbc \ unixodbc-dev \ apt-transport-https \ debconf-utils \ gcc \ libct4 \ libsybdb5 \ tdsodbc \ sqsh \ mlocate \ sudo \ gfortran ENV PATH="/opt/mssql-tools/bin:${PATH}" RUN useradd -u 5555 -m -d /home/shiny -c "shiny user" shiny ADD . /home/shiny/ RUN chown -R shiny:shiny /home/shiny RUN chmod 755 /home/shiny/install_sql.sh WORKDIR /home/shiny RUN Rscript installRpackages.R RUN chmod 755 /home/shiny/install_sql.sh && /home/shiny/install_sql.sh RUN R -e "install.packages('devtools')" RUN R -e "devtools::install_github('rstudio/DT')" RUN R -e "devtools::install_github('timelyportfolio/parcoords')" RUN R -e "devtools::install_github('ropensci/plotly') ; library(plotly)" RUN R -e "devtools::install_github('rstudio/crosstalk',force=TRUE) ; library(crosstalk)" RUN R -e "install.packages(c('plotly'), dependencies = TRUE, repos='https://cran.rstudio.com/')" RUN wget "http://security.debian.org/debian-security/pool/updates/main/o/openssl/libssl1.0.0_1.0.1t-1+deb8u7_amd64.deb" RUN sudo apt install ./libssl1.0.0_1.0.1t-1+deb8u7_amd64.deb USER shiny EXPOSE 7777 CMD Rscript start.R 

And finally, install_sql.sh, called by the Docker file:

 curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - curl https://packages.microsoft.com/config/ubuntu/16.10/prod.list > /etc/apt/sources.list.d/mssql-release.list apt-get update ACCEPT_EULA=Y apt-get install msodbcsql # optional: for bcp and sqlcmd ACCEPT_EULA=Y apt-get install mssql-tools # optional: for unixODBC development headers apt-get install unixodbc-dev 
+8
bash sql-server docker sqlcmd
source share
2 answers

Judging by the nmap output you shared with, I think this is a firewall problem or SQL Server itself is blocking access. According to man nmap :

The state is open, filtered, closed or not filtered [...] Filtered. means a firewall, filter, or other network obstruction is blocking the port, so Nmap cannot determine if it is open or closed.

Reading the output sqlcmd ( A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible ) also points in this direction according to this Microsoft post , which also offers some possible solutions.

IF SQL Server is self-managed, you can check its logs to see why it is refusing your connection, and add a firewall rule to allow access from your container. IF this is not the case, you may need to talk to the administrator of this server and ask him to add your IP address to the firewall list / list of accepted connections in the server configuration file.

If the firewall is not your problem, try applying the settings below to your SQL Server and re-check the connection.

Set β€œListen All” to β€œNo” in SQL Server Configuration Manager> SQL Server Network Configuration> Protocols for [Instance Name]. And also under the change of IP address 127.0.0.1 to [ip] used for connection. do not forget to restart SQL Server!

Another tip: check your firewall (or temporarily disable it for testing). Also enable remote connections in the properties of SQL Server> Connections. See above posts.

Life was safer: nc -zv <ip> 1433
He must say that the connection to port 1433 [tcp / ms-sql-s] is successful!

The source is here .

+4
source share

Reading from your question, I assume that you want to connect to the local SQL Server from within Docker.

SQL Server can be connected to TCP / IP:

  • Open SQL Server Configuration Manager and make sure TCP / IP is enabled,

  • Verify that SQL Server is listening on all IP addresses.

0
source share

All Articles