I am learning docker of golang from Meet the example application.
I build the image
docker build --tag docker-gs-ping .
Then run the image
docker run --publish 8080:8080 docker-gs-ping
But it failed
curl http://localhost:8080/
curl: (7) Failed to connect to localhost port 8080 after 9 ms: Connection refused
The message from the build
[+] Building 5.7s (15/15) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 706B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> resolve image config for docker.io/docker/dockerfile:1 2.7s
=> CACHED docker-image://docker.io/docker/dockerfile:1@sha256:93bfd3b68c109427185cd78b4779fc82b484b0b7618e36d0f104d4d801e66d25 0.0s
=> [internal] load build definition from Dockerfile 0.0s
=> [internal] load metadata for docker.io/library/golang:1.19 2.5s
=> [internal] load .dockerignore 0.0s
=> [1/6] FROM docker.io/library/golang:1.19@sha256:3025bf670b8363ec9f1b4c4f27348e6d9b7fec607c47e401e40df816853e743a 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 6.08kB 0.0s
=> CACHED [2/6] WORKDIR /app 0.0s
=> CACHED [3/6] COPY go.mod go.sum ./ 0.0s
=> CACHED [4/6] RUN go mod download 0.0s
=> CACHED [5/6] COPY *.go ./ 0.0s
=> CACHED [6/6] RUN CGO_ENABLED=0 GOOS=linux go build -o /docker-gs-ping 0.0s
=> exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:450e165ac38773da5e606b4f5833bfcfed01da74f9f3feef61945a4b805c46c6 0.0s
=> => naming to docker.io/library/docker-gs-ping 0.0s
The message from the run
____ __
/ __/___/ / ___
/ _// __/ _ \/ _ \
/___/\__/_//_/\___/ v4.10.2
High performance, minimalist Go web framework
https://echo.labstack.com
____________________________________O/_______
O\
⇨ http server started on [::]:8080
lsof -i:8080
would get a node with name chriss-mbp:60590->172.17.0.4:http-alt (SYN_SENT)
Another tried:
docker inspect \
-f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' 6c7d941c2d19
It returns 172.17.0.4
The result is
curl 172.17.0.4:8080
curl: (28) Failed to connect to 172.17.0.4 port 8080 after 75008 ms: Operation timed out
Anyone suggestion and idea is appreciated. Thank in advance.