无法使用cURL访问Docker容器。

huangapple go评论52阅读模式
英文:

Cannot curl to the docker container

问题

以下是翻译好的部分:

我构建了Docker镜像

...
ENV PORT=8080
ENV ADDRESS=0.0.0.0

EXPOSE 8080
CMD ["node", "/usr/app/src"]

我可以通过docker run来运行它

[HttpFastifyServer]: 在地址0.0.0.0:8080上初始化服务器
[HttpFastifyServer]: └── (空根节点)
    ├── / (POST)
    │   └── / (POST)
    └── * (OPTIONS)

[Process]: 进程已初始化

但我无法使用curl访问它。

$ curl -X POST http://0.0.0.0:8080/
curl: (7) 连接到0.0.0.0端口8080失败:连接被拒绝
$ curl -X POST http://127.0.0.1:8080/
curl: (7) 连接到127.0.0.1端口8080失败:连接被拒绝
$ curl -X POST http://localhost:8080/
curl: (7) 连接到localhost端口8080失败:连接被拒绝

我看不到任何IP地址

$ docker inspect myImage:1.0.0  | grep "IPAddress"
$

有什么想法吗?

英文:

I build the docker image

...
ENV PORT=8080
ENV ADDRESS=0.0.0.0

EXPOSE 8080
CMD ["node", "/usr/app/src"]

I can run it by docker run

[HttpFastifyServer]: Initializing server on address 0.0.0.0:8080
[HttpFastifyServer]: └── (empty root node)
    ├── / (POST)
    │   └── / (POST)
    └── * (OPTIONS)

[Process]: Process initialized

But I cannot curl it.

$ curl -X POST http://0.0.0.0:8080/
curl: (7) Failed to connect to 0.0.0.0 port 8080: Connection rejected
$ curl -X POST http://127.0.0.1:8080/
curl: (7) Failed to connect to 127.0.0.1 port 8080: Connection rejected
$ curl -X POST http://localhost:8080/
curl: (7) Failed to connect to localhost port 8080: Connection rejected

I don't see any ip address

$ docker inspect myImage:1.0.0  | grep "IPAddress"
$

Any ideas?

答案1

得分: 1

如果您在容器中暴露了应用程序的端口8080,并且希望从外部通过端口8080访问它,您需要将-p 8080:8080添加到您的docker run命令中。

英文:

If you expose port 8080 of your app in the container and you want to access it from the outside on port 8080 as well, you need to add -p 8080:8080 to your docker run command.

huangapple
  • 本文由 发表于 2023年5月6日 20:45:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76188961.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定