gpt4 book ai didi

python - docker python flask 得到 "Do you want to continue"然后 "executor failed"

转载 作者:行者123 更新时间:2023-12-04 18:37:19 26 4
gpt4 key购买 nike

尝试一个简单的python flask web app在 docker 20.10.2 中,构建 2291f61。
执行:docker build -t hello-world .开始正常(请参见下文),但以:

#6 2.866 After this operation, 305 MB of additional disk space will be used.
#6 2.866 Do you want to continue? [Y/n] Abort.
------
executor failed running [/bin/sh -c apt-get install python3-pip]: exit code: 1
我需要以某种方式回答这个问题吗?还有其他工作方法吗?
编辑 1: $ docker build -t flask-tutorial:latest 。 # 做同样的事情。
编辑 2:使用来自 @tentative 的 install -y 想法会更进一步。
 > [4/6] RUN apt-get install -y flask:
#7 0.742 Reading package lists...
#7 2.103 Building dependency tree...
#7 2.389 Reading state information...
#7 2.665 E: Unable to locate package flask
------
executor failed running [/bin/sh -c apt-get install -y flask]: ex
it code: 100
编辑 3:代码 here构建图像。
编辑 4:Dockerfile
FROM ubuntu 

RUN apt-get update
RUN apt-get install -y python3-pip
# add -y to skip the y/n prompt and install
#RUN apt-get install -y python3-pip flask
RUN apt-get install -y flask

ADD app.py /
WORKDIR /

EXPOSE 5000

CMD [“python3”,”app.py”]
编辑 5:新的 docker 文件构建工作。但:
$ docker run -i -t --name frog hello-world
/bin/sh: 1: [“python3”,”app.py”]: not found
编辑 6:将上面的开盘和收盘报价更改为中性报价。从主机运行时应用程序运行良好。容器得到一个:27.0.0.1 拒绝连接。
编辑 7:尝试:
docker run -it -p 5000:5000 --name frog hello-world . 
这会导致连接被拒绝(firefox)、空响应(chrome、edge 和 opera)。这是在关闭防御者的 Windows 10 上。
编辑 8:做一个
if __name__ == '__main__':
app.run(host='0.0.0.0')
然后一个
curl 127.0.0.1:5000 -v
从服务器获得空回复。
编辑 9:仅使用: app.run("0.0.0.0"有效!
原始输出。
   ray@rays8350 /cygdrive/d/ray/docker/flask/myapp
$ docker build -t hello-world .
[+] Building 4.9s (7/9)
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 32B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/ubuntu:latest 1.6s
=> [1/6] FROM docker.io/library/ubuntu@sha256:703218c0465075f4425e58fac0 0.0s
=> => resolve docker.io/library/ubuntu@sha256:703218c0465075f4425e58fac0 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 28B 0.0s
=> CACHED [2/6] RUN apt-get update 0.0s
=> ERROR [3/6] RUN apt-get install python3-pip 3.2s
------
> [3/6] RUN apt-get install python3-pip:
#6 0.588 Reading package lists...
#6 1.927 Building dependency tree...
#6 2.258 Reading state information...
#6 2.683 The following additional packages will be installed:
#6 2.683 binutils binutils-common binutils-x86-64-linux-gnu build-essential
#6 2.683 ca-certificates cpp cpp-9 dirmngr dpkg-dev fakeroot file g++ g++-9 g
c gcc-9
#6 2.683 gcc-9-base gnupg gnupg-l10n gnupg-utils gpg gpg-agent gpg-wks-client
#6 2.683 gpg-wks-server gpgconf gpgsm gpgv libalgorithm-diff-perl
#6 2.683 libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan5 libasn1-8
heimdal
#6 2.683 libassuan0 libatomic1 libbinutils libc-dev-bin libc6 libc6-dev libcc
-0
#6 2.684 libcrypt-dev libctf-nobfd0 libctf0 libdpkg-perl libexpat1 libexpat1-
ev
#6 2.684 libfakeroot libfile-fcntllock-perl libgcc-9-dev libgdbm-compat4 libg
bm6
#6 2.684 libgomp1 libgssapi3-heimdal libhcrypto4-heimdal libheimbase1-heimdal
#6 2.684 libheimntlm0-heimdal libhx509-5-heimdal libisl22 libitm1 libkrb5-26-
eimdal
#6 2.684 libksba8 libldap-2.4-2 libldap-common liblocale-gettext-perl liblsan
#6 2.684 libmagic-mgc libmagic1 libmpc3 libmpdec2 libmpfr6 libnpth0 libperl5.
0
#6 2.684 libpython3-dev libpython3-stdlib libpython3.8 libpython3.8-dev
#6 2.684 libpython3.8-minimal libpython3.8-stdlib libquadmath0 libreadline8
#6 2.685 libroken18-heimdal libsasl2-2 libsasl2-modules libsasl2-modules-db
#6 2.685 libsqlite3-0 libssl1.1 libstdc++-9-dev libtsan0 libubsan1 libwind0-h
imdal
#6 2.686 linux-libc-dev make manpages manpages-dev mime-support netbase opens
l patch
#6 2.686 perl perl-modules-5.30 pinentry-curses python-pip-whl python3 python
-dev
#6 2.686 python3-distutils python3-lib2to3 python3-minimal python3-pkg-resour
es
#6 2.686 python3-setuptools python3-wheel python3.8 python3.8-dev python3.8-m
nimal
#6 2.687 readline-common xz-utils zlib1g-dev
#6 2.690 Suggested packages:
#6 2.690 binutils-doc cpp-doc gcc-9-locales dbus-user-session libpam-systemd
#6 2.690 pinentry-gnome3 tor debian-keyring g++-multilib g++-9-multilib gcc-9
doc
#6 2.690 gcc-multilib autoconf automake libtool flex bison gdb gcc-doc gcc-9-
ultilib
#6 2.690 parcimonie xloadimage scdaemon glibc-doc locales git bzr gdbm-l10n
#6 2.690 libsasl2-modules-gssapi-mit | libsasl2-modules-gssapi-heimdal
#6 2.690 libsasl2-modules-ldap libsasl2-modules-otp libsasl2-modules-sql
#6 2.690 libstdc++-9-doc make-doc man-browser ed diffutils-doc perl-doc
#6 2.690 libterm-readline-gnu-perl | libterm-readline-perl-perl libb-debug-pe
l
#6 2.690 liblocale-codes-perl pinentry-doc python3-doc python3-tk python3-ven
#6 2.690 python-setuptools-doc python3.8-venv python3.8-doc binfmt-support
#6 2.690 readline-doc
#6 3.070 The following NEW packages will be installed:
#6 3.070 binutils binutils-common binutils-x86-64-linux-gnu build-essential
#6 3.070 ca-certificates cpp cpp-9 dirmngr dpkg-dev fakeroot file g++ g++-9 g
c gcc-9
#6 3.070 gcc-9-base gnupg gnupg-l10n gnupg-utils gpg gpg-agent gpg-wks-client
#6 3.071 gpg-wks-server gpgconf gpgsm libalgorithm-diff-perl
#6 3.071 libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan5 libasn1-8
heimdal
#6 3.072 libassuan0 libatomic1 libbinutils libc-dev-bin libc6-dev libcc1-0
#6 3.072 libcrypt-dev libctf-nobfd0 libctf0 libdpkg-perl libexpat1 libexpat1-
ev
#6 3.073 libfakeroot libfile-fcntllock-perl libgcc-9-dev libgdbm-compat4 libg
bm6
#6 3.073 libgomp1 libgssapi3-heimdal libhcrypto4-heimdal libheimbase1-heimdal
#6 3.073 libheimntlm0-heimdal libhx509-5-heimdal libisl22 libitm1 libkrb5-26-
eimdal
#6 3.073 libksba8 libldap-2.4-2 libldap-common liblocale-gettext-perl liblsan
#6 3.074 libmagic-mgc libmagic1 libmpc3 libmpdec2 libmpfr6 libnpth0 libperl5.
0
#6 3.075 libpython3-dev libpython3-stdlib libpython3.8 libpython3.8-dev
#6 3.075 libpython3.8-minimal libpython3.8-stdlib libquadmath0 libreadline8
#6 3.077 libroken18-heimdal libsasl2-2 libsasl2-modules libsasl2-modules-db
#6 3.077 libsqlite3-0 libssl1.1 libstdc++-9-dev libtsan0 libubsan1 libwind0-h
imdal
#6 3.077 linux-libc-dev make manpages manpages-dev mime-support netbase opens
l patch
#6 3.078 perl perl-modules-5.30 pinentry-curses python-pip-whl python3 python
-dev
#6 3.078 python3-distutils python3-lib2to3 python3-minimal python3-pip
#6 3.079 python3-pkg-resources python3-setuptools python3-wheel python3.8
#6 3.080 python3.8-dev python3.8-minimal readline-common xz-utils zlib1g-dev
#6 3.083 The following packages will be upgraded:
#6 3.086 gpgv libc6
#6 3.106 2 upgraded, 113 newly installed, 0 to remove and 4 not upgraded.
#6 3.106 Need to get 72.4 MB of archives.
#6 3.106 After this operation, 305 MB of additional disk space will be used.
#6 3.106 Do you want to continue? [Y/n] Abort.
------
executor failed running [/bin/sh -c apt-get install python3-pip]: exit code: 1

ray@rays8350 /cygdrive/d/ray/docker/flask/myapp
$

最佳答案

您应该更改 RUN Dockerfile 中带有 apt-get 的行在他们使用-y标志跳过要求您确认"is"。
教程中的 Dockerfile 实际上似乎已经过时或有错误。您需要使用 pip3现在安装Flask并且还包括 -y在您的 apt-get 中标记命令。我从教程中编辑了 Dockerfile 并在下面发布:

FROM ubuntu

RUN apt-get update -y && \
apt-get install -y python3-pip && \
pip3 install Flask

COPY app.py /

WORKDIR /

EXPOSE 5000

CMD ["python3","app.py"]
编辑 this answer 修复 Windows 上的连接问题,您可以通过将 Python 应用程序中的 main 函数从以下位置更改来解决此问题:
if __name__ == '__main__':
app.run()
对此:
if __name__ == '__main__':
app.run('0.0.0.0')
原因是你需要 Flask 绑定(bind)到 0.0.0.0而不是容器中的localhost接口(interface),否则不会转发到容器外。修复该问题后,您应该可以通过 localhost:5000 访问该应用程序。在您的主机上。

关于python - docker python flask 得到 "Do you want to continue"然后 "executor failed",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66381323/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com