昨天,我发现我的机器(MacOS蒙特雷)上仍有一个容器在运行.我在StackOverflow上搜索我的问题的答案,但我try 的任何东西都不起作用.
我先做了docker ps
,然后做了docker stop <container-ID>
,但Web应用程序仍在端口0.0.0.0:80
上运行.
我不记得我是什么时候运行这个容器的,但它是在开发Dash Ploly应用程序时运行的.
在上述try 失败后,我try 了:
docker system prune --all --force --volumes
它从我的系统中删除了所有容器和图像(它确实起作用了,因为图像确实从我的Docker Desktop列表中消失了).
然后我重新启动了电脑,但Web应用程序仍然在那里.
然后,我运行命令:
sudo lsof -i -P -n | grep 80
这给出了我的输出:
assistant 480 cconsta1 25u IPv4 0x7f28d5520c917253 0t0 UDP *:*
Google 730 cconsta1 80u IPv6 0x7f28d5520a8477c3 0t0 UDP *:5353
Google 730 cconsta1 89u IPv6 0x7f28d5520a8480f3 0t0 UDP *:5353
Slack\x20 4259 cconsta1 23u IPv4 0x7f28d54d343d66cb 0t0 TCP 192.168.10.1:51807->3.65.102.105:443 (ESTABLISHED)
Slack\x20 4259 cconsta1 26u IPv4 0x7f28d54d339966cb 0t0 TCP 192.168.10.1:51809->3.65.102.105:443 (ESTABLISHED)
httpd 4418 root 4u IPv6 0x7f28d53edaecb713 0t0 TCP *:80 (LISTEN)
httpd 4422 _www 4u IPv6 0x7f28d53edaecb713 0t0 TCP *:80 (LISTEN)
httpd 4431 _www 4u IPv6 0x7f28d53edaecb713 0t0 TCP *:80 (LISTEN)
httpd 4433 _www 4u IPv6 0x7f28d53edaecb713 0t0 TCP *:80 (LISTEN)
httpd 4434 _www 4u IPv6 0x7f28d53edaecb713 0t0 TCP *:80 (LISTEN)
我试着终止这些进程,看看有没有办法,sudo kill -9 <PID>
,但也没有效果.
最后,我清理了浏览器的缓存,并判断了Web应用程序是否在私密模式下运行,但它仍然可以运行.
我不记得我用哪个Dockerfile
来运行这个容器,但这个是最接近的:
FROM python:3.10
# EXPOSE 8050
WORKDIR /app
COPY . .
COPY models /app/models/
RUN pip install -r requirements.txt
EXPOSE 8050
CMD ["gunicorn", "-b", "0.0.0.0:8050", "--reload", "app:server"]
该映像可能是使用以下工具构建的:
docker build -f Dockerfile -t app:latest .
并使用以下工具运行:
docker run -p 80:8050 app:latest
这是requirements.txt
号文件:
numpy
pandas
plotly
dash
gunicorn
dash-bootstrap-components
scikit-learn
xgboost
app.py
文件如下所示:
import time
import dash
import dash_bootstrap_components as dbc
import pickle
import numpy as np
import plotly.graph_objs as go
from dash import Input, Output, State, dcc, html
# import tensorflow as tf
# from tensorflow import keras
# from keras.models import load_model
#import xgboost
import re
app = dash.Dash(external_stylesheets=[
dbc.themes.COSMO])
# Include the server option to become able to deploy online
server = app.server
# Code for the app
if __name__ == "__main__":
app.run_server(debug=True, host="0.0.0.0",port="8050", use_reloader=True)
#app.run_server(debug=True)
命令docker --version
返回:
Docker version 20.10.24, build 297e128
编辑:我认为该映像实际上是使用restart always
命令运行的:
docker run --restart always -p 80:8050 app:latest