如何在 Docker 中正确启动 nginx
How to properly start nginx in Docker
我希望 Docker 容器中的 nginx 托管一个简单的静态 hello world html 网站。我想简单地从 "docker run imagename" 开始。为此,我将 运行 参数添加到 Docker 文件中。我想要这样做的原因是我想在下一步中将应用程序托管在 Cloud Foundry 上。不幸的是,我在这样做时遇到以下错误。
Docker文件
FROM nginx:alpine
COPY . /usr/share/nginx/html
EXPOSE 5000
CMD ["nginx -d -p 5000:5000"]
错误
Error starting userland proxy: Bind for 0.0.0.0:5000: unexpected error Permission denied.
来自 ::
https://docs.docker.com/engine/reference/builder/#expose
EXPOSE does not make the ports of the container accessible to the host. To do that, you must use either the -p flag to publish a range of ports or the -P flag to publish all of the exposed ports. You can expose one port number and publish it externally under another number
CMD ["nginx -d -p 5000:5000"]
您添加 docker 文件
来自 nginx:alpine
它已经启动了 nginx。
从 docker 文件
构建之后
你应该在
上使用它
docker run -d -p 5000:5000 <your_image>
编辑:
如果要使用docker端口80->机器端口5000
docker run -d -p 5000:80 <your_image>
我希望 Docker 容器中的 nginx 托管一个简单的静态 hello world html 网站。我想简单地从 "docker run imagename" 开始。为此,我将 运行 参数添加到 Docker 文件中。我想要这样做的原因是我想在下一步中将应用程序托管在 Cloud Foundry 上。不幸的是,我在这样做时遇到以下错误。
Docker文件
FROM nginx:alpine
COPY . /usr/share/nginx/html
EXPOSE 5000
CMD ["nginx -d -p 5000:5000"]
错误
Error starting userland proxy: Bind for 0.0.0.0:5000: unexpected error Permission denied.
来自 :: https://docs.docker.com/engine/reference/builder/#expose
EXPOSE does not make the ports of the container accessible to the host. To do that, you must use either the -p flag to publish a range of ports or the -P flag to publish all of the exposed ports. You can expose one port number and publish it externally under another number
CMD ["nginx -d -p 5000:5000"] 您添加 docker 文件 来自 nginx:alpine 它已经启动了 nginx。 从 docker 文件
构建之后你应该在
上使用它docker run -d -p 5000:5000 <your_image>
编辑: 如果要使用docker端口80->机器端口5000
docker run -d -p 5000:80 <your_image>