小编典典

无法在Docker上运行Golang应用程序

go

我正在尝试运行此项目-https://github.com/JumboInteractiveLimited/codetest

我已经下载了Docker工具箱,并执行了GitHub页面上提到的build和run命令,但是当我尝试访问http:localhost:8080时,该页面仍然不可用。

当我尝试再次执行运行时,Docker说

"$ ./run.sh
Listening on http://localhost:8080
C:\Program Files\Docker Toolbox\docker.exe: Error response from daemon:    driver failed programming external connectivity on endpoint quirky_mcnulty (32af4359629669ee515cbc07d8bbe14cca3237979f37262882fb0288f5d6b6b8): Bind for 0.0.0.0:8080 failed: port is already allocated."

编辑 :澄清一下,我只有在第二次运行时才收到该错误。当我首先运行run命令时,它没有抱怨。我再次运行它只是为了确认它正在运行。

最初运行时,我得到以下信息:

$ ./run.sh
Listening on http://localhost:8080
2017/10/24 13:51:53 Waiting...

阅读 417

收藏
2020-07-02

共1个答案

小编典典

更改run.sh以将端口8080替换为8082

#!/bin/bash
echo "Listening on http://localhost:8082"
docker run -p 8082:80 codetest

如果该端口已在使用中,则将端口更改为8082,根据您的可用端口将该端口再次更改为其他端口。

如果您使用的是Windows

netsh interface portproxy add v4tov4 listenport=8082 listenaddress=localhost connectport=8082 connectaddress=192.168.99.100(IP of the Docker)

这是有关使用docker
Windows主机解决方案在Windows中扩展端口的帮助性讨论

2020-07-02