Mountebank imposter ports not accessible when mountebank started using dotnet-testcontainers - docker

I am using dotnet-testcontainers https://github.com/HofmeisterAn/dotnet-testcontainers to spin up a container with mountebank in my xUnit test.
I can successfully create a mountebank client and create an imposter successfully.
The issue is that when the test is run, the app tries to make a call to the imposter on http://localhost:3000 and gets connection refused.
I can successfully open http://localhost:2525 and can see Mountebank default page. So mountebank is running fine. I also confirmed that the imposter was created successfully on port 3000 by looking at docker container log.
I also tried to use Postman to make a call to my imposter at http:localhost:3000 and get connection refused.
What could be the issue? Is this an issue that port 3000 in the docker container is not exposed or something? Below is my code:
MountebankClient mbClient = new MountebankClient();
var testcontainersBuilder = new TestcontainersBuilder<TestcontainersContainer>()
.WithImage("bbyars/mountebank")
.WithName("mountebank")
.WithPortBinding(2525, false)
.WithHostname("localhost");
var testContainers = testcontainersBuilder.Build();
await testContainers.StartAsync();
var testImposter = mbClient.CreateHttpImposter(3000);
testImposter.AddStub().ReturnsBody(HttpStatusCode.OK, File.ReadAllText(#".\Stubs\testImposter.json"));
mbClient.Submit(testImposter);

Might be useful for someone else who would face this issue. Figured out what the issue was. I was not mapping the host port and the imposter port in the container. Read about published ports https://docs.docker.com/config/containers/container-networking/ and used WithExposedPort(3000) and then did port binding of that port with host port using WithPortBinding(3000,3000) where the first port in this method is host port and second port is container port.
var testcontainersBuilder = new TestcontainersBuilder<TestcontainersContainer>()
.WithImage("bbyars/mountebank")
.WithName("mountebank")
.WithPortBinding(2525, 2525)
.WithExposedPort(3000)
.WithExposedPort(3100)
.WithPortBinding(3000, 3000)
.WithPortBinding(3100, 3100)
.WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(2525))
.WithHostname("localhost");

Related

Accessing webserver inside WSL from Windows(chrome)

I'm using WSL(v2) and have a web server running inside it.
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
kind-control-plane Ready control-plane 3d21h v1.25.0
And I can ping my "website" from within WSL [ping mysite.com] just fine
On my Windows side, I have Docker Desktop running.
Under Containers:
NAME IMAGE STATUS PORTS
kind-control-plane kindest/node:<none> Running 443,42725,80
I have also enabled all [WSL] related options under Docker Desktop -> Settings
I want to access this website in Chrome and tried:
localhost:443 = err 400
localhost:42725 = Client sent an HTTP request to an HTTPS server. With https, err 403
localhost:80 = err 404
I also tried adding the port 42725 to my firewall allowed list but nothing seems to change.
I searched and found multiple Q&As pointing me here:
https://learn.microsoft.com/en-us/windows/wsl/networking
I tried these:
netsh interface portproxy add v4tov4 listenport=80listenaddress=0.0.0.0 connectport=80connectaddress={hostname -I}
netsh interface portproxy add v4tov4 listenport=443listenaddress=0.0.0.0 connectport=443connectaddress={hostname -I}
but nothing changes.
However, when I do this
netsh interface portproxy add v4tov4 listenport=42725listenaddress=0.0.0.0 connectport=42725connectaddress={hostname -I}
And then try to restart:
$ docker start kind-control-plane
Error response from daemon: Ports are not available: exposing port TCP 127.0.0.1:42725 -> 0.0.0.0:0: listen tcp 127.0.0.1:42725: bind: An attempt was made to access a socket in a way forbidden by its access permissions.
Error: failed to start containers: kind-control-plane
I also tried a completely different [listenport] but it didn't work either.
I'm actually not sure what ports to put inside the listenport/connectport options. Also, should I change listenaddress=0.0.0.0 to something else?
Any suggestions? Thanks!

Vagrant cant connect to local host

Hello i am having trouble with vagrant setup.
So i am trying to ping serverless API which runs on http://localhost:3000/ (and it's outside vagrant project).
Right now my vagrant project runs on https://localhost:4443/.
Overall trying to CURL request from vagrant project to another serverless project.
Tried to use http://localhost:3000/ in CURL request but getting Failed to connect to localhost port 3000: Connection refused
Tried to use VM ip 10.0.2.15 address same
Tried to do port forwarding in vagrantfile config.vm.network :forwarded_port, guest: 3000, host: 3000 and use machine IP address 192.168.0.16, getting empty response from server, when i try to do telnet 192.168.0.16 3000 getting
Trying 192.168.0.16...
Connected to 192.168.0.16.
Escape character is '^]'.
Connection closed by foreign host.
Any idea what to try?
I had to use VM IP address something like
curl -X GET http://10.0.2.2:3000
These errors may be caused due to follow reasons, ensure the following steps are followed. To connect the local host with the local virtual machine(host). Here, I'am connecting http://localhost:3001/ to the http://abc.test Steps to be followed:
1.We have to allow CORS, placing Access-Control-Allow-Origin: in header of request may not work. Install a google extension which enables a CORS request.*
2.Make sure the credentials you provide in the request are valid.
3.Make sure the vagrant has been provisioned. Try vagrant up --provision this make the localhost connect to db of the homestead.
Try changing the content type of the header. header:{ 'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8;application/json' }
this point is very important.

weblogic in docker trying to use the public port in the container when 7101:7001 port mapping is used

I am starting a WebLogic 12.2.1.4 admin server in docker from my docker-compose.yml file.
I use different port mapping, not the default 7001.
My docker port mapping is this: 7101:7001
Everything works fine, except this: I constantly get the following exception when I click on the Deployment menu on the web console:
<Feb 12, 2021 5:11:21,002 PM UTC> <Notice> <JMX> <BEA-149535> <JMX Resiliency Activity Server=All Servers : Resolving connection list DomainRuntimeServiceMBean>
javax.ws.rs.ProcessingException: java.net.ConnectException: Tried all: '1' addresses, but could not connect over HTTP to server: 'localhost', port: '7101'
failed reasons:
[0] address:'localhost/127.0.0.1',port:'7101' : java.net.ConnectException: Connection refused
The WL admin server tries to use the public docker port 7101 in the container but actually, WL is listening on the default 7001 port inside the container. Port 7101 is only used from the host machine, and of course, WL is not listening on port 7101 in the container.
My workaround is the following:
Check the IP address of the admin-server container with docker inspect <container-name>
Open the WL console using the container private IP address, e.g.: http://172.19.0.2:7001/console
In this case, the exception does not appear
But if I open the WL console from http://localhost:7101/console which is the mapped port to the host machine by docker, then the exception appears
Maybe this is a WL user interface issue? But I am not sure.
Any idea why this happening?

Spray on AWS Bind to localhost/127.0.0.1:80 failed

I have set up everything for spray on my AWS instance.
I am also able to run the sample spray-template successfully.
But the issue is spray-template uses port 8080 to bind when I change port from 8080 to 80.
I am facing below mentioned error.
Bind to localhost/127.0.0.1:80 failed
Below is line from my Boot.Scala file
IO(Http) ? Http.Bind(service, interface = "localhost", port = 8080
Can anyone help me with this?
Thank You.

Yaws server is not accessible outside of local network

I am trying to host erlang Yaws web server on my Raspberry Pi.
I am using no-ip as dynamic DNS.
My router is Thomson ST780. On the router I have made port forwarding from port 50001 to port 8081 on my Raspberry Pi.
My server is accessible from within the local network only and shows index.yaws as expected. However, I want it to be accessible from the internet. I believe the problem lies in Yaws config, because I have disabled firewall on my router, and also firewall is disabled on Pi.
The Yaws config part that I believe is wrongly configured looks like this:
<server my_application_name.no-ip.org>
port = 8081
listen = 0.0.0.0
docroot = /home/pi/erl/airport
dir_listing = false
auth_log = true
statistics = true
appmode = <cgi-bin, yaws_appmod_cgi>
</server>
I have also tried adding
<auth> allow = all </auth>
and putting local IP address in listen part and it is still not working.
Can anybody see the problem with this configuration?
I am also using the same way of port forwarding on my router for SSH and SSH is accessible from the internet.
EDIT: The install that I have made is local_install, as recommended here: http://yaws.hyber.org/configuration.yaws and perhaps that might be a problem.

Resources