I am learning docker,this is my dockerfile . I start a http service in docker and expose 9999 port,here is the content:
FROM golang:1.20
LABEL authors="tom"
WORKDIR /app
COPY . /app
RUN go build -o main .
EXPOSE 9999
ENTRYPOINT ["/app/main"]
step 1 : I build the dockerfile to generate docker image called "cache-go".
step 2 : I run the docker service by using:docker run --net=host -p 8899:9999 cache-go.
step 3 : I test my web api in docker shell:curl "http://localhost:9999/api?key=Tom" , it's successful.
step 4 : I try to access the web-api in my real host computer :"http://localhost:8899/api?key=Tom". failed
step1 to 3 are right,I tried to open the firewall and enable IpEnablerouting setting,but still failed. I'm confused about the problem,please help me, I will be appreciate for your help.
I tried to open the firewall and enable IpEnablerouting setting,but still failed.
-------------done------------ I edited 127.0.0.1 to 0.0.0.0 and solved the problem. I understand it by reading this blog pythonspeed.com/articles/docker-connection-refused