Ray Tayek
Ray Tayek

Reputation: 10003

docker python flask gets " Do you want to continue" then "executor failed"

Trying a simple python flask web app in docker 20.10.2, build 2291f61.

Doing the: docker build -t hello-world . starts out ok (please see below), but ends with:

#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

Do I need to answer the question with a yes somehow? Is there some other workarond?

Edit 1: $ docker build -t flask-tutorial:latest . # does the same thing.

Edit 2: Using the install -y idea from @tentative gets a lot further.

 > [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

Edit 3: the code here builds an image.

Edit 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”]

Edit 5: The new docker file build works. but:

$ docker run -i -t --name frog hello-world
/bin/sh: 1: [“python3”,”app.py”]: not found

Edit 6: changed the open and closed quotes above to neutral quotes. app runs fine when run from host. container get a: 27.0.0.1 refused to connect.

Edit 7: trying:

docker run -it -p 5000:5000 --name frog hello-world . 

This gets a connection refused (firefox), an empty response (chrome, edge, and opera). This is on windows 10 with the defender turned off.

Edit 8: doing a

if __name__ == '__main__':
    app.run(host='0.0.0.0')

then a

curl 127.0.0.1:5000 -v

gets an empty reply from server.

Edit 9: using just: app.run("0.0.0.0" works!

original output.

   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
    $

Upvotes: 1

Views: 5787

Answers (1)

cam
cam

Reputation: 5198

You should change the RUN lines in the Dockerfile with apt-get in them to use the -y flag to skip asking you to confirm "yes".

The Dockerfile in the tutorial actually seems out of date or has errors in it. You need to use pip3 now to install Flask and also include the -y flag in your apt-get commands. I edited the Dockerfile from the tutorial and posted below:

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"]

EDIT To fix the connection issues on Windows from this answer, you can fix this by changing the main function in the Python app from:

if __name__ == '__main__':
    app.run()

to this:

if __name__ == '__main__':
    app.run('0.0.0.0')

The reason is that you need Flask to bind to 0.0.0.0 instead of the localhost interface in the container, otherwise, it won't forward outside the container. After fixing that, you should be able to access the app at localhost:5000 on your host machine.

Upvotes: 6

Related Questions