英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论