0

I try to connect to MSSQL server from within docker container which has been port forwarded to this linux server. However this forwarded port were listening on 127.0.0.1

root@v2:~# netstat -alpn | grep 1433
tcp        0      0 127.0.0.1:1433          0.0.0.0:*               LISTEN      3285/sshd: root
tcp6       0      0 ::1:1433                :::*                    LISTEN      3285/sshd: root

ip addr shows below result.

eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:50:56:01:07:78 brd ff:ff:ff:ff:ff:ff
    inet 10.1.3.10/24 brd 10.1.3.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::250:56ff:fe01:778/64 scope link
       valid_lft forever preferred_lft forever

 docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:99:6a:d0:14 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
   valid_lft forever preferred_lft forever
inet6 fe80::42:99ff:fe6a:d014/64 scope link
   valid_lft forever preferred_lft forever

I have tried instructions from here and here, but still failed to connect to the sql server from within container.

Ping from inside docker to 10.1.3.10 is successful. Telnet from inside docker to 10.1.3.10 on port 22 is successful.

iptables -A PREROUTING -t nat -i docker0 -p tcp --dport 1433 -j REDIRECT --to-port 1433
iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 1433 -j DNAT --to 127.0.0.1:1433
  • Try using the external ip address when you are first running your docker container and so -p ip:hostPort:containerPort – Raman Sailopal Jul 20 '18 at 9:12
  • done that but still cant... – MyASHeS Jul 24 '18 at 3:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.