rails-sqlserver / tiny_tds

TinyTDS - Simple and fast FreeTDS bindings for Ruby using DB-Library.
Other
607 stars 189 forks source link

Adaptive Server connection failed (xx.xx.xx.xx:1433) (TinyTds::Error) run in docker container #441

Closed takanamito closed 5 years ago

takanamito commented 5 years ago

I'm trying to connect to SQL Server 2014 using tiny_tds in docker container.
TinyTDS::Client.new raises exception.
Adaptive Server connection failed (xx.xx.xx.xx:1433) (TinyTds::Error)

I tried to build by several version of docker (17.09.0, 18.09.0, 18.09.1).
It was found to connect DB successful with container only built by docker 18.09.2 (Docker for mac).

The same error occured other than macOS.

Sample Code

I tried to build some docker containers.
But only docker 18.09.2(Docker for Mac) can build container image connectable to db.
Other tiny_tds ver(2.1.1), freeTDS ver(1.1.1, 1.1.10, 1.1.11) too.

Dockerfile

FROM ruby:2.6.3

ARG FREETDS_VER

RUN wget http://www.freetds.org/files/stable/freetds-$FREETDS_VER.tar.gz
RUN tar -xzf freetds-$FREETDS_VER.tar.gz
WORKDIR freetds-$FREETDS_VER
RUN ./configure --prefix=/usr/local --with-tdsver=7.3
RUN make
RUN make install

ARG TINY_TDS_VER

RUN gem i tiny_tds -v $TINY_TDS_VER
ADD ./sample.rb /home/sample.rb

CMD ["ruby","/home/sample.rb"]

sample.rb

require 'tiny_tds'

client = TinyTds::Client.new(username: 'user', password: 'password', host: 'xx.xx.xx.xx', port: 1433, database: 'db_name')
results = client.execute 'SELECT GETDATE()'

results.each { |result| p result }

Build and run.

$ docker build . -t my_tiny_tds:latest --build-arg FREETDS_VER=1.00.111 --build-arg TINY_TDS_VER=2.1.2
$ docker run my_tiny_tds:latest
/usr/local/bundle/gems/tiny_tds-2.1.2/lib/tiny_tds/client.rb:60:in `connect': Adaptive Server connection failed (xx.xx.xx.xx) (TinyTds::Error)
        from /usr/local/bundle/gems/tiny_tds-2.1.2/lib/tiny_tds/client.rb:60:in `initialize'
        from /home/sample.rb:3:in `new'
        from /home/sample.rb:3:in `<main>'

Environment

aharpervc commented 5 years ago

~When you do docker run, you'll need to forward the port to the container host. eg, docker run -p 1433:1433 my_tiny_tds:latest~

e: sorry, misread what was running; thought this was a database container. Still, check that the server is otherwise accessible (including the server host ip from inside the container environment) :)

sonots commented 5 years ago

Hi, I am SRE from the same company with takanamito, and investigated this problem. The root cause was https://github.com/FreeTDS/freetds/issues/299 "TLS handshake failed on Debian buster", not caused by Docker version.

Following change worked as a workaround for now.

- FROM ruby:2.6.3
+ FROM ruby:2.6.3-stretch
juan-alencar-vagas commented 2 years ago

I had to reinstall freetds, so then it worked.

sudo apt-get install wget sudo apt-get install build-essential sudo apt-get install libc6-dev wget ftp://ftp.freetds.org/pub/freetds/stable/freetds-1.2.tar.gz tar -xzf freetds-1.2.tar.gz cd freetds-1.2 ./configure --prefix=/usr/local --with-tdsver=7.3 sudo make sudo make install