I am dockerized a golang application and i am trying to access the application. Application running in port 8007
I am running the container the following command
docker run --name sample_go_app -p 7000:8007 sample_go
After tried curl http://localhost:7000 but getting error
curl: (56) Recv failure: Connection reset by peer
main.go
...
srv := &http.Server {
Handler: router,
Addr: "localhost:8007",
}
...
You're binding the socket to localhost address which cannot be reached from outside of your container. You should only add the port part in the address so that your process accepts connection from any network interface. You can define your server this way:
srv := &http.Server {
Handler: router,
Addr: ":8007",
}
Related
I have a problem with connecting by curl to simple akka http server living in docker container.
Here is source code:
sbt new akka/akka-http-quickstart-scala.g8
added sbt native packager plugin to plugins.sbt
addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.9.11")
and small change in build.sbt at the end:
libraryDependencies ++= Seq(
...
),
dockerExposedPorts := Seq(8080)
)
.enablePlugins(JavaAppPackaging, DockerPlugin)
so docker exposed ports and enable plugins.
If I will run it with network host like:
docker run --network host image-name:0.1
it work fine, but without network host or -p 8080:8080 or without does not work,
every time I get
curl: (56) Recv failure: Connection reset by peer
can it be smth connected with interface param ?
Http().newServerAt("localhost", 8080).bind(routes)
I started mailhog in container: docker run --rm -ti -p 8025:8025 -p 1025:1025 mailhog/mailhog. Web UI works, but connection fails:
curl smtp://172.17.0.2:1025 --mail-from a#b.com --mail-rcpt c#d.com
curl: (28) Failed to connect to 172.17.0.2 port 1025 after 31641 ms: Operation timed out
172.17.0.2 is container IP address, i'm using Docker Desktop for Mac. Why connection is not established?
I solved this problem by connecting mailhog container to a network defined in docker-compose.yml.
I am trying to run a Go app binary in a docker container. The app has some gRPC request being listen and server on:
http.ListenAndServe("localhost:8081", nil)
In my docker-compose.yaml. I have a service of the app mapped to 8081:
golangAPP:
build:
context: .
dockerfile: ./docker/golangAPP/Dockerfile
depends_on:
- setup
ports:
- 8081:8081
After docker-compose up I can see the verbose that the app is being served.
But I still cannot reach it. curl -X OPTIONS http://localhost:8081 return
curl: (56) Recv failure: Connection reset by peer
If I run the binary locally without docker, then I can send request to the app.
Any suggestion? I did some googling and some point to firewall issue. But I am not sure how to proceed.
If you do:
http.ListenAndServe("localhost:8081", nil)
this will listen to connections from the loopback interface. When running within a container, this will only accept connections coming from within that container (or if you're running this in a k8s pod, within the same pod). So:
http.ListenAndServe(":8081", nil)
This will accept both loopback and external connections (external to the container).
I know this error has been posted before on StackOverflow and many solutions/answers are available too. But, I've already gone through all those answers and couldn't find any viable solution for me.
I'm running a Hyperledger Fabric network with single peer and orderer. Their Docker containers have exposed the following ports. 7051:7051 & 7053:7053 on peer, 7050:7050 on orderer. I'm trying to configure Prometheus to analyse the metrics by following the official documentation .
As mentioned in the documentation, I'm exposing my local machine's 9443 port to port 9443 of peer docker container by mapping it as 9443:9443 in ports section of docker-compose.yaml. When I run curl 0.0.0.0:9443, I get curl: (56) Recv failure: Connection reset by peer error.
However, when I run the command curl 0.0.0.0:9443/logspec in my peer container I get the desired result which is {"spec":"info"}. The two commands mentioned above are different but I've also tried running the command curl 0.0.0.0:9443/logspec in my local machine to which I got the same error response.
Running the command curl -v 0.0.0.0:9443 results in following response.
* About to connect() to 0.0.0.0 port 9443 (#0)
* Trying 0.0.0.0...
* Connected to 0.0.0.0 (0.0.0.0) port 9443 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: 0.0.0.0:9443
> Accept: */*
>
* Recv failure: Connection reset by peer
* Closing connection 0
curl: (56) Recv failure: Connection reset by peer
I read in many of the answers that I might be a firewall issue. But even after disabling my firewall using the command systemctl disable firewalld, it's not working.
cat etc/os-release response
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"
curl --version response
curl 7.29.0 (x86_64-redhat-linux-gnu) libcurl/7.29.0 NSS/3.34 zlib/1.2.7 libidn/1.28 libssh2/1.4.3
I request you not to mark this question as duplicate as I've already gone through all the possible scenarios mentioned here.
First of all please check if there is firewall. Disable it.
Then remove the IP address provided in core.yaml file in operations tab. So that line will look like a below:
operations:
# host and port for the operations server
listenAddress: :9443
This change worked for me.
I managed to set up ghost blog on my raspberry pi.I was able to access the index page on curl without issues. But I had to restart my container. After restarting the container, I cannot access the site anymore.
I get the following error when I run the command
curl http://localhost:4500
curl: (56) Recv failure: Connection reset by peer
If I spin up a new container it works fine. How can I rectify the above error?
I managed to isolate the issue. It's seems to be an issue with ip binding but am unsure how to reolve it.
Docker Rails app fails to be served - curl: (56) Recv failure: Connection reset by peer
As suggested in the above question, I tried curl inside the container and it works. I also tried from the host using the container ip and that works as well. It fails when i curl usint localhost:portnumber.