简体   繁体   English

如何将 Docker 容器暴露给 Web

[英]How to expose Docker container to the web

I am new to the fabulous world of docker and star twith asking a quite noobish question I think.我是 docker 神话般的世界的新手,我认为我首先提出了一个非常愚蠢的问题。 But first, a little information about myself:但首先,关于我自己的一些信息:

I am working with exist-db and plan to move it to docker.我正在使用exist-db并计划将其移至docker。 So set it up on the server, I thought and followed this instructions.所以在服务器上设置它,我想并遵循了这个说明。 I am not importing my app, yet, as I want to familiarize with how it works, before I move towards “the cloud”.我还没有导入我的应用程序,因为我想在转向“云”之前熟悉它的工作原理。

I am running docker on a server, which I access using Putty.我在使用 Putty 访问的服务器上运行 docker。 I have set it up properly, even my existdb container works:我已经正确设置了它,即使我的existdb容器也能工作:

curl localhost:8080

gives me the html-output I am expecting from existDB.给了我我期望从existDB 得到的html 输出。 However, when I attempt to [server-IP]:8080 in firefox, I cannot access it.但是,当我尝试在 Firefox 中使用 [server-IP]:8080 时,我无法访问它。

I know I haven't configured anything else yet, besides when I started the container, but the following.我知道我还没有配置任何其他东西,除了当我启动容器时,但以下内容。

docker run -it -d -p 8080:8080 -p 8443:8443 --name exist existdb/existdb:latest

Shouldn't this bind my container[8080] to my host[8080] (or 8443 for that matter), so that I should in theory be able to [Host-ip]:8080 and see the exist Interface?这不应该将我的容器 [8080] 绑定到我的主机 [8080](或 8443),以便理论上我应该能够 [Host-ip]:8080 并看到存在的接口?

I do not want to use host-mode, as I'll probably have several apps up& running in the future, so that I think it better to separate the interfaces.我不想使用主机模式,因为我将来可能会启动和运行多个应用程序,因此我认为最好将接口分开。

Following this answer here and I quote按照这里的答案,我引用

By default, Docker exposes container ports to the IP address 0.0.0.0 (this matches any IP on the system).默认情况下,Docker 将容器端口暴露给 IP 地址 0.0.0.0(这匹配系统上的任何 IP)。 If you prefer, you can tell Docker which IP to bind on.如果您愿意,可以告诉 Docker 绑定哪个 IP。 To bind on IP address 10.0.0.3, host port 80, and container port 8080:要绑定 IP 地址 10.0.0.3、主机端口 80 和容器端口 8080:

docker run -p 10.0.0.3:80:8080 <your image>

following the comments i have tried to regenrate the setuation and as you can see按照评论,我尝试重新生成设置,如您所见

CONTAINER ID        IMAGE                    COMMAND                  CREATED             STATUS                   PORTS                                            NAMES
9eebf8c6f3b2        existdb/existdb:latest   "java org.exist.star…"   2 minutes ago       Up 2 minutes (healthy)   0.0.0.0:8080->8080/tcp, 0.0.0.0:8443->8443/tcp   exist

so you need to run the command like the following docker run -it -d -p 0.0.0.0:8080:8080 -p 0.0.0.0:8443:8443 --name exist existdb/existdb:lates所以你需要像下面这样运行命令docker run -it -d -p 0.0.0.0:8080:8080 -p 0.0.0.0:8443:8443 --name exist existdb/existdb:lates

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM