访问在 Docker 容器内运行的应用程序 URL。

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

accessing an application url running inside a docker container

问题

我有一个在Docker容器内正常运行的应用程序:

  • 在http://127.0.0.1:5000上运行

但是这个URL:http://127.0.0.1:5000 无法从我的本地机器浏览器访问。
我尝试更改我的docker run命令中的端口,但没有成功...

英文:

I've an application running fine inside the docker container :

 * Running on http://127.0.0.1:5000

but this url: http://127.0.0.1:5000 is not accessible from the browser in my local machine.
I tried to change the ports in my docker run command, but no luck...

答案1

得分: 1

你可以在运行容器时使用 -p--publish 选项将容器的端口绑定到本地机器上的一个端口!例如,如果容器内的应用程序正在监听端口 5000,您可以使用以下命令将容器的端口 5000 绑定到本地机器的端口 5000:

docker run -p 5000:5000 <image_name>

使用此命令运行容器后,您可以在本地机器的浏览器中使用 http://127.0.0.1:5000 访问应用程序。祝好运!

英文:

you can bind the container's port to a port on your local machine using the -p or --publish option when running the container!

for example, if the application inside the container is listening on port 5000, you can use the command

docker run -p 5000:5000 &lt;image_name&gt;

to bind port 5000 of the container to port 5000 on your local machine,and after running the container with this command, you can access the application in your local machine's browser using http://127.0.0.1:5000.

Good luck!

huangapple
  • 本文由 发表于 2023年7月6日 19:34:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76628409.html
匿名

发表评论

匿名网友

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

确定