昨天我发现一个容器还在我的机器上运行(macOS Monterey)。我在 StackOverflow 上搜索了我的问题的答案,但我尝试过的任何方法都没有用。
我做了一个
docker ps
然后一个docker stop <container-ID>
但网络应用程序仍在端口0.0.0.0:80
中运行。
我不记得我是什么时候运行这个容器的,但那是在 Dash Plotly 应用程序的开发过程中。
以上失败后我试了:
docker system prune --all --force --volumes
从我的系统中删除了所有容器和图像(它确实有效,因为图像确实从我的 Docker 桌面列表中消失了)。
然后我重新启动了我的电脑,但网络应用程序仍然存在。
然后我运行命令:
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>
但这也没有用。
最后,我清除了浏览器缓存并检查了网络应用程序是否以私有模式运行但它仍然有效。
我不记得我曾经用哪个
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