python - 无法使用 Windows Ubuntu 应用程序连接到 Docker

标签 python windows docker ubuntu flask

我正在关注本教程: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?
为了执行这些命令,我​​使用的是适用于 Windows 的 Ubuntu 18.04 LTS 应用程序。我也下载了 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)```

最佳答案

运行 sudo su在运行您的其他命令之前已过时,因为它通过添加前缀 sudo 以 super 用户身份运行.

“根目录”不是指您的根用户目录,而是您的项目的根目录,您的 Dockerfile 存储在其中。在运行 docker build 之前,您必须导航到该目录。命令。

关于python - 无法使用 Windows Ubuntu 应用程序连接到 Docker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60742113/

相关文章:

python - Django 管理更改列表页面中未选择新行 (\n)

python - 在 SQLAlchemy 应用程序的单元测试中使用 Alembic?

windows - Perl 脚本无故挂起

powershell - 在 windowsservercore 中使用 powershell 挂载 ISO 镜像失败

hadoop - 在 docker swarm 外部访问 hdfs

python - Sqlalchemy 返回 SELECT 命令的不同结果(query.all)

python - 使用 BeautifulSoup 在第一个子标签之前提取文本

缺少 Java 1.8.65 javac

python - 路径名打开时间太长?

docker - 无法在 COCO 注释器中创建数据集和加载图像