简体   繁体   English

如何暴露 Docker 容器

[英]How to expose a Docker container

I have this Dockerfile written.我写了这个Dockerfile

FROM python:3.6

WORKDIR /usr/src/app

EXPOSE 8080

CMD [ "python3", "-m http.server" ] //even tried CMD [ "python3", "-m", "http.server" ]

I built the image with this:我用这个构建了图像:

docker build -t --name server .

and I ran a container from the image like this:我从图像中运行了一个容器,如下所示:

docker run -d -p 8080:8080 --name web server

But when I hit < host-url >:8080但是当我点击 < host-url >:8080

It doesn't work.它不起作用。

Can somebody please help me?有人能帮帮我吗?

You are trying to run the Python SimpleHTTPServer which is served in port 8000 by default.您正在尝试运行默认在端口8000中提供服务的 Python SimpleHTTPServer。

Either your Dockerfile should expose 8000 instead of 8080您的Dockerfile应该公开8000而不是8080

EXPOSE 8000

Or, change the command to run it in port 8080或者,更改命令以在端口8080中运行它

CMD ["python3", "-m",  "http.server", "8080"]

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

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