我正在学习本教程:https://www.geeksforgeeks.org/dockerize-your-flask-app/
一切正常,直到我进入这一步:“构建Docker镜像,确保您在项目的根目录中,然后运行以下命令。”
要进入根目录,我输入sudo su,然后运行以下命令,如本教程所示:
sudo docker build --tag flask-docker-demo-app .
当我运行上面的命令时,我得到了这样的响应:
ERRO[0000] failed to dial gRPC: cannot connect to the Docker daemon. Is docker daemon' running on this host?: dial unix /var/run/docker.sock: connect: no such file or directory. Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
为了执行这些命令,我使用了Ubuntu 18.04 LTS App for windows。我也下载了Docker Desktop。
此外,我不认为这有任何影响,但我有一个与教程提供的不同的demo.py。这是我的demo.py:
from flask import Flask
server = Flask(__name__)
@server.route('/')
# ‘/’ URL is bound with hello_world() function.
def hello_world():
return 'Hello World'
import sys
print(sys.version)
import dash
import dash_core_components as dcc
import dash_html_components as html
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, server = server, routes_pathname_prefix = '/dash/', external_stylesheets=external_stylesheets)
app.layout = html.Div(children=[
html.H1(children='Hello Dash'),
html.Div(children='''
Dash: A web application framework for Python.
'''),
dcc.Graph(
id='example-graph',
figure={
'data': [
{'x': [1, 2, 3], 'y': [4, 1, 22], 'type': 'bar', 'name': 'SF'},
{'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': u'Montréal'},
],
'layout': {
'title': 'Dash Data Visualization'
}
}
)
])
if __name__ == '__main__':
app.run_server(debug=True)```发布于 2020-03-18 23:06:54
在运行其他命令之前运行sudo su已过时,因为它是通过添加前缀sudo以超级用户身份运行的。
“根目录”并不是指根用户目录,而是项目的根目录,Dockerfile就存储在这个根目录中。在运行docker build命令之前,您必须导航到该目录。
发布于 2020-03-18 23:22:23
您应该将您的用户放在Docker组中,这样您就不需要执行sudo命令即可使用docker。(事实上,您当然不应该这样做!)
然后..。那么,Docker守护程序是否正在运行?看起来你可能需要(重新)安装它。
https://stackoverflow.com/questions/60742113
复制相似问题