Docker run --publish 8080:8080 docker-gs-ping response Connection refused

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.

Did you try to run the command inside the terminal? First you should establish that the application itself is generally working as expected:

docker exec -ti docker-gs-ping curl http://localhost:8080

If the application is reachable from inside the container, please share the output of docker info

docker exec -ti docker-gs-ping curl http://localhost:8080

It said: Error: No such container: docker-gs-ping
Output of docker info is

Client:
 Context:    colima
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc., v0.9.1)
  compose: Docker Compose (Docker Inc., v2.13.0)
  dev: Docker Dev Environments (Docker Inc., v0.0.5)
  extension: Manages Docker extensions (Docker Inc., v0.2.16)
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc., 0.6.0)
  scan: Docker Scan (Docker Inc., v0.22.0)

Server:
 Containers: 4
  Running: 3
  Paused: 0
  Stopped: 1
 Images: 10
 Server Version: 20.10.20
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runtime.v1.linux runc io.containerd.runc.v2
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
 runc version: 5fd4c4d144137e991c4acebb2146ab1483a97925
 init version: 
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 5.15.82-0-virt
 Operating System: Alpine Linux v3.16
 OSType: linux
 Architecture: aarch64
 CPUs: 2
 Total Memory: 1.93GiB
 Name: colima
 ID: R4X3:TGV7:PPAX:ZQLU:U5OQ:FT7T:JGRQ:7XC2:VJOE:ZFWB:QCPQ:HUUX
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

My bad. Of couse you need to use the container name or id:

docker exec -ti <container name or id> curl http://localhost:8080

You can find the name and id in the output of docker ps

docker exec -ti <container name or id> curl http://localhost:8080

Result

Hello, Docker! <3

I uninstall Docker Desktop and reinstall docker:

netstat -tulpn, is the port open on host?