Docker port 開不起來 - Linux

Table of Contents

自己寫的 Dockerfile

FROM python:3
WORKDIR /home/src/app
COPY requirements.txt /home/src
RUN pip install --no-cache-dir -r /home/src/requirements.txt
CMD [ "python", "app_main.py" ]
EXPOSE 5000

使用 docker run -p 5000:5000 -v src:/home/src/app -ti image 執行

* Serving Flask app 'app_main' (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

但是使用 telnet ip:5000 或是 telnet localhost:5000 都只會得到以下結果
Trying ip...
telnet: Unable to connect to remote host: Connection refused

Dockerfile 有 expose,docker run 也有指定 port 但是就是連不到
我有什麼地方搞錯了嗎?


--

All Comments

Lauren avatarLauren2021-07-27
改Listen在 0.0.0.0:5000
Blanche avatarBlanche2021-07-28
你從host連進去 對docker來說不是localhost
Kyle avatarKyle2021-07-29
app.run(host=0.0.0.0)
Tracy avatarTracy2021-07-31
喔喔,原來是 flask 啟動方式的問題,感謝兩位