【问题标题】:Can't connect to Docker using Windows Ubuntu App无法使用 Windows Ubuntu 应用程序连接到 Docker
【发布时间】:2020-03-18 14:57:50
【问题描述】:

我正在关注本教程: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)```

【问题讨论】:

    标签: python windows docker ubuntu flask


    【解决方案1】:

    在运行其他命令之前运行sudo su 已过时,因为它通过添加前缀sudo 以超级用户身份运行。

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

    【讨论】:

    • ...但是,当我自己犯了那个错误时,我收到了不同的消息(不是“docker daemon 正在运行吗?”)。 (我仍然定期这样做。)正如我在上面评论的那样,我认为 OP 在这里有不止一个问题。
    【解决方案2】:

    您应该将您的用户放在docker 组中,这样您就不必发出sudo 来使用Docker。 (事实上​​,你当然应该永远不要那样做!)

    然后......“嗯, Docker 守护进程正在运行吗?”看起来您可能需要(重新)安装它。

    【讨论】:

    • 感谢您的帮助!当你说(重新)安装它时,你指的是 Docker 守护进程吗?如果是这样,我将如何安装守护程序?我认为这将是 docker windows 应用程序中的设置。此外,您的评论是正确的,现在当我在没有 sudo 的情况下运行时,我收到有关我的 requirements.txt 文件的以下错误:The command '/bin/sh -c pip install -r requirements.txt' returned a non-zero code, failed to shutdown container
    猜你喜欢
    • 2018-06-11
    • 1970-01-01
    • 2021-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-24
    • 2019-11-07
    相关资源
    最近更新 更多