简体   繁体   English

Docker -p 和 Dockerfile 的一些问题

[英]Some questions of Docker -p and Dockerfile

1: docker run -d -p 3000:3000 images 1: docker run -d -p 3000:3000 images

If i up a localhost:3000 server in container,how can i open it in my machine browser, what's the ip?如果我在容器中启动了一个localhost:3000服务器,我如何在我的机器浏览器中打开它,ip 是多少? I've tried localhost:3000 or 0.0.0.0:3000 .我试过localhost:30000.0.0.0:3000


2: I use docker pull ubuntu and docker run it, after updating and deploying the server i commmited it.So now i have one ubuntu and a new image. 2:我使用docker pull ubuntudocker run它,在更新和部署服务器后我提交了它。所以现在我有一个ubuntu和一个新图像。

Next time i run a container using this new image, The shell scripts still needs to be sourced, also the server needs to reopened again.下次我使用这个新镜像运行容器时,仍然需要获取 shell 脚本,还需要再次重新打开服务器。

How can i commit the image that it can source the scripts and deployed by itself when i docker run it.当我docker run它时,我如何提交它可以提供脚本并自行部署的图像。

Thanks.谢谢。

I don't quite understand questions 2 or 3, can you add more context?我不太明白问题 2 或 3,您可以添加更多上下文吗?

Regarding your question about using -p , you should be able to visit in your browser using http://localhost:3000/ .关于使用-p的问题,您应该可以使用http://localhost:3000/在浏览器中访问。 However that assumes a couple of things are true.然而,这假设有几件事是正确的。

First, you used -p 3000:<container-port> - looks good on this point.首先,您使用了-p 3000:<container-port> - 在这一点上看起来不错。

Second, the image you have run exposed port 3000 ( EXPOSE 3000 ).其次,您运行的图像暴露了端口 3000 ( EXPOSE 3000 )。

And third, the service running in the container is listening on 0.0.0.0:3000 .第三,容器中运行的服务正在侦听0.0.0.0:3000 If it is listening on localhost inside the container , then the port export will not work.如果它在容器内侦听 localhost ,则端口导出将不起作用。 Each container has its own localhost which is usable only inside the container.每个容器都有自己的本地主机,它只能容器内部使用。 So it needs to be listening on all IPs inside the container, in order for outside connections to reach the service from outside of the container.因此它需要监听容器内的所有 IP,以便外部连接能够从容器外部访问服务。

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

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