[英]docker port exposing issue
I have a flask application that I'm trying to dockerize but the ports are not getting exposed properly.我有一个正在尝试 dockerize 的 Flask 应用程序,但端口没有正确暴露。
DockerFile文件
FROM tiangolo/uwsgi-nginx-flask:python3.7
LABEL Name=testAPP Version=0.0.1
EXPOSE 5000
ADD . /app
WORKDIR /app
# Using pip:
RUN python3 -m pip install -r requirements.txt
ENTRYPOINT [ "python3" ]
CMD ["application.py" ,"runserver","-h 0.0.0.0"]
Docker Build is successful: Docker Build 成功:
docker build --rm -f "Dockerfile" -t testAPP .
Docker Run is building the image successfully Docker Run 正在成功构建镜像
docker run -device -expose 5000:5000 testAPP
Also tried,也试过了,
docker run --rm -d -p 443:443/tcp -p 5000:5000/tcp -p 80:80/tcp testAPP
But when I try to access the site it throws an error但是当我尝试访问该站点时,它会引发错误
site can't be reached error网站无法访问错误
Flask App(Inside the APP) Flask App(APP内)
if __name__ == '__main__':
app.run(host='127.0.0.1', port=5000)
On Execution of the command在执行命令时
Docker container ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8724cdb38e14 testAPP "/entrypoint.sh pyth…" 15 seconds ago Up 13 seconds 80/tcp, 443/tcp, 0.0.0.0:5000->5000/tcp funny_galois
Defining a port as exposed doesn't publish the port by itself.将端口定义为公开端口不会自行发布端口。 Try with the flag -p , like:
尝试使用标志-p ,例如:
-p container_port:local_port
-p 容器端口:本地端口
example:例子:
docker run -p 8080:8080 -v ~/Code/PYTHON/ttftt-recipes-manager:/app python_dev
But before running try to check if there is something else that already running on the specified port like:但是在运行之前尝试检查是否有其他东西已经在指定的端口上运行,例如:
lsof -i :PORTNUM
and after with something like:之后是这样的:
docker logs my_container
Make sure you're mapping your localhost port to the container's port确保将本地主机端口映射到容器的端口
docker run -p 127.0.0.1:8000:8000 your_image docker run -p 127.0.0.1:8000:8000 your_image
And once you're application is in the container, you want to run your app with the host set to 0.0.0.0一旦你的应用程序在容器中,你想在主机设置为 0.0.0.0 的情况下运行你的应用程序
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.