Cannot connect to remote SQL Server instance from app in container - docker

Pretty new to docker, but I just created an image and it seems to start up fine until it attempts to connect to a remote SQL server. That is, a SQL server that is on it's own VM and is normally accessible via a host (e.g. mydatabase.mydomain.com). This problem doesn't present when it's run out of visual studio; the database is fine and it is reachable.
I suspect that it has something with docker networking. I tried exposing 1433 with no luck. I've also tried running it with --net=host also no luck. The errors are being output by NServiceBus where it's trying to communiciate with AzureServiceBus as well as SQL Server stating that the server was not responding or is unreachable.
The Dockerfile
FROM microsoft/windowsservercore
WORKDIR /command
EXPOSE 8002
EXPOSE 1433
COPY . /command
ENTRYPOINT ["NServiceBus.Host.exe"]
Any ideas or insight would be good.

It can be a firewall issue on SQL Server host.
Here is an article on how to host a multi container application on a windows container.

Related

Unable to receive data from socket on Docker Windows

I have a webserver listening on some port. I dockerize this server and publish its port with the command:
docker run -p 8080:8080 image-tag
Now I write a short Java client socket connecting to localhost on this port (it is able to connect). However, when I read data from this socket via the readLine function, it always returns me null. It shouldn't. Can someone point me some direction on how to troubleshoot this? Things I have tried:
This webserver and client works fine without docker.
Using my docker installation, I'm able to pull the getting-started app and it works fine. (means there is no problem with my docker, it still can publish port)
My docker pulls only the openjdk:latest as the base image. Other than that, nothing special.
The docker is Linux Docker on Windows Host.
The port the webserver is running on is correct and the same as the published port.
I would be very happy if someone could help.
By making the server app inside container listen on address 0.0.0.0 instead of localhost, I'm able to solve the problem.

On Windows Server '19 Can docker run side by side with IIS?

I built a project (react/express) and used Docker and docker-compose to stand up my local development environment. I'm ready to deploy now and I have a Windows Server 2019 VM that is currently hosting PHP applications on IIS.
Is it possible to add Docker to my server and host my containerized application without impacting my existing IIS sites (Essentially run the container and IIS side by side)? If so, how do I bind the container/application to a URL within IIS?
I have really struggled to find Docker information on this topic.
Also, while I'm at it, will I need to pay for Docker Enterprise Edition?
Yes, you can, IIS by default will use port 80 and 443. Hence, to make it run side-by-side:
When run your docker do not mapping to port 80. docker run -p 8080:80 your_docker_handler for example. Hence you can access you IIS using http://server-ip and for docker http://server-ip:8080
or else,
You can do reverse proxy from IIS to your docker if you want to access docker without the port. But this one will need more effort and maybe some adjustment on your app code inside docker as well

Nifi install using Docker - CanĀ“t access the webserver

I'm new to both docker and Nifi, I found this command that installs via docker and used it on a virtual machine that I have in GCP but I would like to access this container via webserver. In docker ps this appears to me:
What command do I need to execute to gain access to the tool via port 8080?
The container has already exposed port 8080 on the host, as evidence by the output 0.0.0.0:8080->8080/tcp. You read that as {HOST_INTERFACE}:{HOST_PORT}->{CONTAINER_PORT}/{PROTOCOL}.
Navigate to http://SERVER_ADDRESS:8080/ (or maybe http://SERVER_ADDRESS:8080/nifi) using your web browser. You may need to modify the firewall rules applied to your VM to ensure that you can access that port from your local machine.

Docker on Windows Connecting to sql server from dotnetcore app

I've built a simple api using asp.net core that returns some data from a sql server database.
It runs fine in VS and from the command line, but when i build and run the app as a docker container on my windows 10 machine when i call the api i keep getting this error
System.Data.SqlClient.SqlException: Connection Timeout Expired. The
timeout period elapsed during the post-login phase. The connection
could have timed out while waiting for server to complete the login
process and respond; Or it could have timed out while attempting to
create multiple active connections. The duration spent while
attempting to connect to this server was - [Pre-Login]
initialization=425; handshake=265; [Login] initialization=5;
authentication=9; [Post-Login] complete=14034; --->
System.ComponentModel.Win32Exception: Unknown error 258
I'm not really sure what this is telling me, it's as if it cant find the sql server machine. Do i have to expose port 1433 somehow in the docker config or when i run the container up?
As Tseng explained in his comment, your containers are in their own network, not in your host's network. You'll want indeed to expose that port (or map to another available port on your host), which you can easily do with Docker Compose. In the example below (that you'd but in a docker-compose.yml file), sql is the name of your database container, 1337 is the local port, and 1433 is the container's port.
sql:
ports:
- "1337:1433"
Not sure if my case was the same as your case, but in my case I was connecting from a docker container to a sql server 2008 R2 running on the host (real pc). I had to install SP3 for sql server 2008 R2 to fix it.
More info here

Connecting to Docker container connection refused - but container is running

I am running 2 spring boot applications: A client and rest-api. The client communicates to the rest-api which communicates to a mongodb database. All 3 tiers are running inside docker containers.
I launch the containers normally specifying the exposed ports in the dockerfile and mapping them to a port on the host machine such as: -p 7070:7070, where 7070 is a port exposed in the Dockerfile.
When I run the applications through the java -jar [application_name.war] command, the application works fine and they all can communicate.
However, when I run the applications in a Docker container I get connection refused error, such as when the client tries to connect to the rest-api I get a connection refused error at http://localhost:7070.
But the command docker ps shows that the containers are all running and listening on the exposed and mapped ports.
I have no clue why the containers aren't recognizing that the other containers are running and listening on their ports.
Does this have anything to do with iptables?
Any help is appreciated.
Thanks
EDIT 1: The applications when ran inside containers work fine on my machine, and they don't throw any connection refused errors. The error only happens on that particular different machine.
I used container linking to solve this problem. Make sure you add --link <name>:<alias> at run-time to the container you want linked. <name> is the name of the container you want to link to and <alias> will be the host/domain of an entry in Spring's application.properties file.
Example:
spring.data.mongodb.host=mongodb if the alias supplied at run-time is 'mongodb':
--link myContainerName:mongodb

Resources