Docker container ports are exposed on Windows but not Ubuntu - docker

I'm developing an Ubuntu based docker image on a windows 10 machine with Docker Desktop. The image has a server app listening for HTTP traffic on port 5000. When I run the image locally on Windows using:
docker run -d -p 5000:5000 dockerImageName /opt/serverApp
Everything works fine, I can go to http://localhost:5000 and see a web interface.
But then I push the image to a repo in Azure then pull it back down onto a Ubuntu Azure VM and execute the same command, the container appears to start correctly but executing:
curl http://localhost:5000
returns:
curl: (7) Failed to connect to localhost port 5000: Connection refused
Not that it should matter but I've also allowed incoming traffic on port 5000 in the network security group the VM is attached to.
If I execute:
sudo lsof -i:5000
Nothing is returned.
Is this an Azure related issue? Are there differences between how a Linux image is run on Windows and a VM on Azure (on Windows Docker Desktop uses a Linux VM to run containers)?

Le sigh it was this:
Docker container will automatically stop after “docker run -d”
Annoying how the behavior changes between Windows and Ubuntu when running containers.

Related

Unable to access Docker container running in WSL2

I am new to containers and Docker. On my Windows 10 laptop (Version 20H2 Build 19042.630) I have WSL2 installed as well as Docker Desktop (Docker Engine v19.03.13). When I run the command below (from the docker documentation):
docker run -d -p 80:80 docker/getting-started
The container starts fine but I am unable to access the container from either within WSL or from the Windows 10 host.
Inside WSL, if I enter curl http://127.0.0.1 it returns the error curl: (7) Failed to connect to 127.0.0.1 port 80: Connection refused
From the Windows 10 host, if I open a browser and attempt to go to http://127.0.0.1 it just throws a 404 error.
From the Windows 10 host, when I open the Docker Desktop app, it shows the container running and listening on port 80 but if I then stop the container...and then attempt to restart it, it throws an error that says:
(HTTP code 500) server error - Ports are not available: listen tcp 0.0.0.0:80: bind: An attempt was made to access a socket in a way forbidden by its access permissions
I have tried completely uninstalling WSL and Docker Desktop and resetting the TCP/IP stack but the end result is the same. I performed the exact same install steps on my desktop PC and everything works fine with no issues. I did notice on the desktop PC that the first time I tried accessing the "getting-started" container that it produced a pop-up to allow the traffic through my firewall. I never got this on the laptop. I compared the firewall rules on the PC to the Laptop and the PC had 4 rules for the com.docker.backed application that the Laptop did not have. I manually duplicated those rules on the laptop but it did not change the behavior any.
EDIT:
After doing more research on this issue...discovered why this is happening. The ports the container is attempting to listen on are excluded for my Laptop. Found the Github issue linked below that had the command netsh interface ipv4 show excludedportrange protocol=tcp that showed the list of excluded ports on my laptop. Seems Hyper-V is what is excluding the ports but the only reason Hyper-V is on the system is for WSL. The Github issue is still open as of today.
Unable to bind ports: Docker-for-Windows & Hyper-V excluding but not using important port ranges #3171
If your docker container uses localhost inside it won't work. I had the same issue with docker inside wsl and the solution was to change IP of underlying service (the one that is run inside docker) to 0.0.0.0.
You can check this by doing docker ps. In my case I ran the docker like this:
docker run --rm -p 8080:8080 hello-python
which was then bind to (part of docker ps output):
0.0.0.0:8080->8080/tcp
So basically the python code had to use 0.0.0.0:8080 instead of localhost:8080

Netstat does not show ports exposed by Docker Windows container

I installed Docker on Windows Server 2019. The version is
Docker version 19.03.5, build 2ee0c57608.
A container was created to run an instance of SQL server. The container started successfully with the following command.
docker run -d -p 1430:1433 test1433
I can login the SQL server with "localhost,1430" as connection string.
However netstat -an does not show the port. External computers cannot access this port.
I checked Docker and netstat: netstat is not showing ports, exposed by docker containers and other URL. However the solutions do not work for me.
Did anyone else encounter the issue?
Thank you

Unable to connect localhost using HyperV Container on Win10 1903

I was just upgraded to Windows 10 1903 from 1809, then my docker become a little bit weird. Here are my current situation:
OS: Microsoft Windows [ver 10.0.18362.116]
Hyper-V: Installed. I have only one VSwitch called Default Switch.
I reinstalled Docker Desktop for Windows v2.0.0.3. (Docker version 18.09.2, build 6247962)
The docker can run without problem. Only the network issue!
Here is what I tried:
Run iis container in "process" isolation mode.
docker run -d --rm -p 80:80 --isolation process mcr.microsoft.com/windows/servercore/iis:windowsservercore-1903
I can connect to port 80 through localhost.
Run iis container in "hyperv" isolation mode.
docker run -d --rm -p 80:80 --isolation hyperv mcr.microsoft.com/windows/servercore/iis:windowsservercore-1903
I can't connect to port 80 through localhost. I was okay before I upgrade to Windows 10 1903.
I almost tried everything I can try. I just can't get my localhost (loopback interface) works.
I tried on the other machine. When docker started, there is a nat VSwitch will be created by docker. It doesn't work on my machine.
I tried to create a new VMSwitch and named nat but doesn't works.
I tried to run .\WindowsContainerNetworking-LoggingAndCleanupAide.ps1 -Cleanup -ForceDeleteAllSwitches using this script. Restart the computer. It doesn't works.
I completely removed Hyper-V and Docker. Reinstall again doesn't works.
I tried to list networks defined in hnsdiag. (hnsdiag list networks) Then deleted the nat network. Restart the HNS service. Restart Docker again. It doesn't work.
May I ask what else I can do for my docker network settings?

connect to server runned in windows docker container

I am a newbie with docker. I need to use it at windows 7*64 , via docker toolbox. I need to make a connection to server below:
Run the server:
docker run -p 4444:4444 mycontainerWithServer
After this i open new docker toolbox window and try to connect to localhost:4444. I get ConnectionRefused error.
Because you are using the Docker toolbox you don't access your containers on localhost. The toolbox uses 192.168.99.100 by default because it is running on a Linux VM. Try replacing localhost with the VM IP.

Docker: Use Host SSH Forwards in container

I try to access a MS SQL Server from within a Docker container.
The problem is, it is only reachable via an SSH tunnel that I can establish on my host machine. I use a local forward for port 1433, that will automatically be established once I connect to the server.
Using SquirrelSQL for example, I can access the Server via 127.0.0.1:1433 with no problem.
But from within my docker container I am unable to do so.
I already tried to run the docker container with --expose 1433 -p 127.0.0.1:1433:1433 but that didn't work out.
Host is running Ubuntu 16.04, the Docker Container is running on some sort of Debian.

Resources