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 upRequest HeadersUser-Agent: PostmanRuntime/7.26.8Accept: */*Postman-Token: <token>Host: 0.0.0.0:6001Accept-Encoding: gzip, deflate, brConnection: 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--
Docker File
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>
output
docker ps
output
$ sudo docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES835e8cb11eee form_ocr "python3 app.py" 16 hours ago Up 40 seconds 0.0.0.0:6001->5000/tcp form_ocr
Best Answer
I had the same problem with fastapi container
Make sure your app is listening on 0.0.0.0 within the container
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.
Try localhost:6001 not internet address
You can also try any of your system local ipaddress , you find ipaddress by typing ifconfig or ipconfig if you are in linux or windows respectively
Same problem with fast-API server inside the container:
To fix let the fast-API server bi running on the host ="0.0.0.0", when you use the uvicorn.run
method because by default the host "127.0.0.1" will be used.
For me this worked:
uvicorn.run(self, host="0.0.0.0", port=port)