'Unable to access docker container Socket hang up error
I have successfully built and started the docker container, it is running perfectly, but when I try to access it [End point url 0.0.0.0:6001] I am getting a "socket hang up" error
GET http://0.0.0.0:6001/
Error: socket hang up
Request Headers
User-Agent: PostmanRuntime/7.26.8
Accept: */*
Postman-Token: <token>
Host: 0.0.0.0:6001
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Earlier it was working fine but when I removed the containers and images and rebuild it then I started getting this error
I am using Postman to make GET request and I also tried Web browser
Can anyone tell me whats the problem
--Update--
Creating containers
# Create Virtual Network
$ sudo docker network create network1
# Using custom network as there are multiple containers
# which communicate with each other
# Create Containers
$ sudo docker build -t form_ocr:latest .
$ sudo docker run -d -p 6001:5000 --net network1 --name form_ocr form_ocr
netstat command output
$ netstat -nltp
...
tcp6 0 0 :::6001 :::* LISTEN -
docker container inspect output
$ sudo docker container inspect <container-id>
docker ps output
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
835e8cb11eee form_ocr "python3 app.py" 16 hours ago Up 40 seconds 0.0.0.0:6001->5000/tcp form_ocr
Solution 1:[1]
Just add this in main.ts, where you listen to the port:
await app.listen(6001, '0.0.0.0', () => console.log(`Listening on port: 6000`));
Add the '0.0.0.0' , it should work.
Solution 2:[2]
I had the same problem with fastapi container
Make sure your app is listening on 0.0.0.0 within the container
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Yadhu Krishna |
| Solution 2 | Dhouibi iheb |
