martes, 18 de junio de 2019

Docker Build running Python Flask CRUD REST APP

Docker corriendo una aplicación CRUD REST phyton y Flask

   El proceso es el siguiente. se parte del archivo Dockerfile que tiene las instrucciones de como se constuirá la imagen de docker. en este caso instala un linux minimalista al cual le instala los paquetes python3 y pip, crea un subdirectorio donde radicaran los fuentes de la aplicación en la imagen docker final, se ejecutan comandos para postinstalación de dependencias de la aplicación python, se expone el puerto 5000 en el contenedor docker, al cual se le indica que Docker debera iniciar ejecución de la aplicación python.

Partimos del subdirectorio donde tenemos la aplicación app.py

(venv) bext@bext-VPCF13WFX:~/workspace/flask-crud-rest-app$ ls
api  app.py  __pycache__  venv


Ejecutando los dos primeros pasos en el archivo Dockerfile tenemos

contenido Dockerfile

FROM alpine:latest

RUN apk add --no-cache python3-dev \
    && pip3 install --upgrade pip

ejecutando en terminal

(venv) bext@bext-VPCF13WFX:~/workspace/flask-crud-rest-app$ docker build -t flaskapp:latest .
Sending build context to Docker daemon  36.62MB
Step 1/2 : FROM alpine:latest
latest: Pulling from library/alpine
e7c96db7181b: Pull complete 
Digest: sha256:769fddc7cc2f0a1c35abb2f91432e8beecf83916c421420e6a6da9f8975464b6
Status: Downloaded newer image for alpine:latest
 ---> 055936d39205
Step 2/2 : RUN apk add --no-cache python3-dev     && pip3 install --upgrade pip
 ---> Running in 3f25b54f2a94
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/community/x86_64/APKINDEX.tar.gz
(1/13) Installing pkgconf (1.6.0-r0)
(2/13) Installing libbz2 (1.0.6-r6)
(3/13) Installing expat (2.2.6-r0)
(4/13) Installing libffi (3.2.1-r6)
(5/13) Installing gdbm (1.13-r1)
(6/13) Installing xz-libs (5.2.4-r0)
(7/13) Installing ncurses-terminfo-base (6.1_p20190105-r0)
(8/13) Installing ncurses-terminfo (6.1_p20190105-r0)
(9/13) Installing ncurses-libs (6.1_p20190105-r0)
(10/13) Installing readline (7.0.003-r1)
(11/13) Installing sqlite-libs (3.28.0-r0)
(12/13) Installing python3 (3.6.8-r2)
(13/13) Installing python3-dev (3.6.8-r2)
Executing busybox-1.29.3-r10.trigger
OK: 105 MiB in 27 packages
Collecting pip
  Downloading https://files.pythonhosted.org/packages/5c/e0/be401c003291b56efc55aeba6a80ab790d3d4cece2778288d65323009420/pip-19.1.1-py2.py3-none-any.whl (1.4MB)
Installing collected packages: pip
  Found existing installation: pip 18.1
    Uninstalling pip-18.1:
      Successfully uninstalled pip-18.1
Successfully installed pip-19.1.1
Removing intermediate container 3f25b54f2a94
 ---> d0bc58770e6e
Successfully built d0bc58770e6e
Successfully tagged flaskapp:latest
(venv) bext@bext-VPCF13WFX:~/workspace/flask-crud-rest-app
 
Podemos verificar la imagen

(venv) bext@bext-VPCF13WFX:~/workspace/flask-crud-rest-app$ docker images 
REPOSITORY     TAG                 IMAGE ID            CREATED             SIZE
flaskapp       latest              d0bc58770e6e        6 minutes ago       97.1MB

Ejecutamos la imagen con modo iterativo y habilitando una terminal

(venv) bext@bext-VPCF13WFX:~/workspace/flask-crud-rest-app$ docker run -it flaskapp /bin/sh
/ # ls
bin    etc    lib    mnt    proc   run    srv    tmp    var
dev    home   media  opt    root   sbin   sys    usr
/ # 

En otra terminal exploramos los procesos de docker activos

bext@bext-VPCF13WFX:~$ docker ps
CONTAINER ID  IMAGE     COMMAND     CREATED        STATUS        PORTS        NAMES
2ab076475cd3  flaskapp  "/bin/sh"   2 minutes ago  Up 2 minutes               hardcore_stallman
bext@bext-VPCF13WFX:~$ 

Se observa nada en PORTS.

Verificamos en el contenedor docker con linux alpine que tenga instalado python3 y pip

/ # python3
Python 3.6.8 (default, Apr  8 2019, 18:17:52) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()
/ # pip

Usage:   
  pip <command> [options]

Commands:
  install                     Install packages.
  download                    Download packages.
  uninstall                   Uninstall packages.
  freeze                      Output installed packages in requirements format.
  list                        List installed packages.
  show                        Show information about installed packages.
  check                       Verify installed packages have compatible dependencies.
  config                      Manage local and global configuration.
  search                      Search PyPI for packages.
  wheel                       Build wheels from your requirements.
  hash                        Compute hashes of package archives.
  completion                  A helper command used for command completion.
  help                        Show help for commands.

General Options:
  -h, --help                  Show help.
  --isolated                  Run pip in an isolated mode, ignoring environment variables and user configuration.
  -v, --verbose               Give more output. Option is additive, and can be used up to 3 times.
  -V, --version               Show version and exit.
  -q, --quiet                 Give less output. Option is additive, and can be used up to 3 times (corresponding to WARNING, ERROR, and
                              CRITICAL logging levels).
  --log <path>                Path to a verbose appending log.
  --proxy <proxy>             Specify a proxy in the form [user:passwd@]proxy.server:port.
  --retries <retries>         Maximum number of retries each connection should attempt (default 5 times).
  --timeout <sec>             Set the socket timeout (default 15 seconds).
  --exists-action <action>    Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort.
  --trusted-host <hostname>   Mark this host as trusted, even though it does not have valid or any HTTPS.
  --cert <path>               Path to alternate CA bundle.
  --client-cert <path>        Path to SSL client certificate, a single file containing the private key and the certificate in PEM format.
  --cache-dir <dir>           Store the cache data in <dir>.
  --no-cache-dir              Disable the cache.
  --disable-pip-version-check
                              Don't periodically check PyPI to determine whether a new version of pip is available for download. Implied
                              with --no-index.
  --no-color                  Suppress colored output
/ # 

Ahora salimos del contenedor con exit, el contenedor se detiene y lo podemos verificar con docker ps que no reporta su ejecución.

/ # exit
(venv) bext@bext-VPCF13WFX:~/workspace/flask-crud-rest-app$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
(venv) bext@bext-VPCF13WFX:~/workspace/flask-crud-rest-app$ 

Ahora consideramos más pasos en el Dockerfile. WORKDIR, COPY y RUN

FROM alpine:latest

RUN apk add --no-cache python3-dev \
    && pip3 install --upgrade pip

WORKDIR /app

COPY . /app

RUN pip3 --no-cache-dir install -r requirements.txt

Ahora generamos de nuevo la imagen

(venv) bext@bext-VPCF13WFX:~/workspace/flask-crud-rest-app$ docker build -t flaskapp:latest .
Sending build context to Docker daemon  36.62MB
Step 1/5 : FROM alpine:latest
 ---> 055936d39205
Step 2/5 : RUN apk add --no-cache python3-dev     && pip3 install --upgrade pip
 ---> Using cache
 ---> d0bc58770e6e
Step 3/5 : WORKDIR /app
 ---> Running in ebbb81b8d41b
Removing intermediate container ebbb81b8d41b
 ---> 68ff8f17bb98
Step 4/5 : COPY . /app
 ---> b156c636e292
Step 5/5 : RUN pip3 --no-cache-dir install -r requirements.txt
 ---> Running in 2fae4dca86c2
Collecting flask (from -r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/9a/74/670ae9737d14114753b8c8fdf2e8bd212a05d3b361ab15b44937dfd40985/Flask-1.0.3-py2.py3-none-any.whl (92kB)
Collecting Werkzeug>=0.14 (from flask->-r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/9f/57/92a497e38161ce40606c27a86759c6b92dd34fcdb33f64171ec559257c02/Werkzeug-0.15.4-py2.py3-none-any.whl (327kB)
Collecting click>=5.1 (from flask->-r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/fa/37/45185cb5abbc30d7257104c434fe0b07e5a195a6847506c074527aa599ec/Click-7.0-py2.py3-none-any.whl (81kB)
Collecting itsdangerous>=0.24 (from flask->-r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/76/ae/44b03b253d6fade317f32c24d100b3b35c2239807046a4c953c7b89fa49e/itsdangerous-1.1.0-py2.py3-none-any.whl
Collecting Jinja2>=2.10 (from flask->-r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/1d/e7/fd8b501e7a6dfe492a433deb7b9d833d39ca74916fa8bc63dd1a4947a671/Jinja2-2.10.1-py2.py3-none-any.whl (124kB)
Collecting MarkupSafe>=0.23 (from Jinja2>=2.10->flask->-r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/b9/2e/64db92e53b86efccfaea71321f597fa2e1b2bd3853d8ce658568f7a13094/MarkupSafe-1.1.1.tar.gz
Installing collected packages: Werkzeug, click, itsdangerous, MarkupSafe, Jinja2, flask
  Running setup.py install for MarkupSafe: started
    Running setup.py install for MarkupSafe: finished with status 'done'
Successfully installed Jinja2-2.10.1 MarkupSafe-1.1.1 Werkzeug-0.15.4 click-7.0 flask-1.0.3 itsdangerous-1.1.0
Removing intermediate container 2fae4dca86c2
 ---> 4a959b0b3a2c
Successfully built 4a959b0b3a2c
Successfully tagged flaskapp:latest
(venv) bext@bext-VPCF13WFX:~/workspace/flask-crud-rest-app$ 

Algo notable de observar es que los dos primeros pasos ejecutados en la construcción anterior de la imagen no son reejecutados, esto por que usa la cache.
El archivo requirements.txt solo tiene una linea conteniendo flask.

La imagen docker es reportada de la siguiente manera, notese el tamaño a incrementado

(venv) bext@bext-VPCF13WFX:~/workspace/flask-crud-rest-app$ docker images
REPOSITORY  TAG                 IMAGE ID            CREATED             SIZE
flaskapp    latest              4a959b0b3a2c        5 minutes ago       134MB

Ahora, debemos ejecutar la aplicación app.py en el contenedor, esto es con la linea ENTRYPOINT que tiene el comando python3 y CMD son los argumentos app.py.  que es lo que se haría en la máquina local para ejecutar la aplicación.
  Ejecutamos la aplicación en la máquina local a manera de demostración.

(venv) bext@bext-VPCF13WFX:~/workspace/flask-crud-rest-app$ python3 app.py
DEBUG:root:Arrancando la aplicacion
 * Serving Flask app "app" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
INFO:werkzeug: * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
INFO:werkzeug: * Restarting with stat
DEBUG:root:Arrancando la aplicacion
WARNING:werkzeug: * Debugger is active!
INFO:werkzeug: * Debugger PIN: 243-904-832
^C(venv) bext@bext-VPCF13WFX:~/workspace/flask-crud-rest-app$ 

Ahora, agregamos al Dockerfile la instrucción para exponer el puerto 5000
y ejecutar la aplicación.
Dockerfile
FROM alpine:latest
RUN apk add --no-cache python3-dev \
    && pip3 install --upgrade pip
WORKDIR /app
COPY . /app
RUN pip3 --no-cache-dir install -r requirements.txt
EXPOSE 5000
ENTRYPOINT ["python3"]
CMD ["app.py"]

Volvemos a contruir la imagen docker

(venv) bext@bext-VPCF13WFX:~/workspace/flask-crud-rest-app$ docker build -t flaskapp:latest .
Sending build context to Docker daemon  36.62MB
Step 1/8 : FROM alpine:latest
 ---> 055936d39205
Step 2/8 : RUN apk add --no-cache python3-dev     && pip3 install --upgrade pip
 ---> Using cache
 ---> d0bc58770e6e
Step 3/8 : WORKDIR /app
 ---> Using cache
 ---> 68ff8f17bb98
Step 4/8 : COPY . /app
 ---> 0bd4cf31ae74
Step 5/8 : RUN pip3 --no-cache-dir install -r requirements.txt
 ---> Running in a06f31c5df5f
Collecting flask (from -r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/9a/74/670ae9737d14114753b8c8fdf2e8bd212a05d3b361ab15b44937dfd40985/Flask-1.0.3-py2.py3-none-any.whl (92kB)
Collecting Jinja2>=2.10 (from flask->-r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/1d/e7/fd8b501e7a6dfe492a433deb7b9d833d39ca74916fa8bc63dd1a4947a671/Jinja2-2.10.1-py2.py3-none-any.whl (124kB)
Collecting Werkzeug>=0.14 (from flask->-r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/9f/57/92a497e38161ce40606c27a86759c6b92dd34fcdb33f64171ec559257c02/Werkzeug-0.15.4-py2.py3-none-any.whl (327kB)
Collecting click>=5.1 (from flask->-r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/fa/37/45185cb5abbc30d7257104c434fe0b07e5a195a6847506c074527aa599ec/Click-7.0-py2.py3-none-any.whl (81kB)
Collecting itsdangerous>=0.24 (from flask->-r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/76/ae/44b03b253d6fade317f32c24d100b3b35c2239807046a4c953c7b89fa49e/itsdangerous-1.1.0-py2.py3-none-any.whl
Collecting MarkupSafe>=0.23 (from Jinja2>=2.10->flask->-r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/b9/2e/64db92e53b86efccfaea71321f597fa2e1b2bd3853d8ce658568f7a13094/MarkupSafe-1.1.1.tar.gz
Installing collected packages: MarkupSafe, Jinja2, Werkzeug, click, itsdangerous, flask
  Running setup.py install for MarkupSafe: started
    Running setup.py install for MarkupSafe: finished with status 'done'
Successfully installed Jinja2-2.10.1 MarkupSafe-1.1.1 Werkzeug-0.15.4 click-7.0 flask-1.0.3 itsdangerous-1.1.0
Removing intermediate container a06f31c5df5f
 ---> e0ea76e2dc6f
Step 6/8 : EXPOSE 5000
 ---> Running in 7baf53671d7f
Removing intermediate container 7baf53671d7f
 ---> 8e1d313bddc1
Step 7/8 : ENTRYPOINT ["python3"]
 ---> Running in 4f7b2a0d9740
Removing intermediate container 4f7b2a0d9740
 ---> dbfc1353e1a1
Step 8/8 : CMD ["app.py"]
 ---> Running in 2c084d02c36f
Removing intermediate container 2c084d02c36f
 ---> 77787fb045e3
Successfully built 77787fb045e3
Successfully tagged flaskapp:latest
(venv) bext@bext-VPCF13WFX:~/workspace/flask-crud-rest-app
 
 
 
 
Ejecutemos la aplicación
(venv) bext@bext-VPCF13WFX:~/workspace/flask-crud-rest-app$ docker run -it flaskapp
DEBUG:root:Arrancando la aplicacion
Traceback (most recent call last):
  File "app.py", line 9, in <module>
    from api import *
  File "/app/api/__init__.py", line 1, in <module>
    from flask_restful import Api
ModuleNotFoundError: No module named 'flask_restful'

Nos reporta un error. No encuentra flask_restful. Para hallar el error, usaremos la estratégia de ejecutar los comandos desde el contenedor en linux. Así que a la imagen le deshabilitaremos la ejecución de comando ENTRYPOINT, para posteriormente desde linea de comandos intentar importar el supuesto paquete flask_restful con pip desde linea de comandos.

(venv) bext@bext-VPCF13WFX:~/workspace/flask-crud-rest-app$ nano Dockerfile
(venv) bext@bext-VPCF13WFX:~/workspace/flask-crud-rest-app$ docker build -t flaskapp:latest .
(venv) bext@bext-VPCF13WFX:~/workspace/flask-crud-rest-app$ docker run -it flaskapp /bin/sh

Dentro del linux del contenedor agregamos la linea flask_restful a requirements.txt
/app # vi requirements.txt
/app # pip3 install -r requirements.txt
Requirement already satisfied: flask in /usr/lib/python3.6/site-packages (from -r requirements.txt (line 1)) (1.0.3)
Collecting flask_restful (from -r requirements.txt (line 2))
  Downloading https://files.pythonhosted.org/packages/17/44/6e490150ee443ca81d5f88b61bb4bbb133d44d75b0b716ebe92489508da4/Flask_RESTful-0.3.7-py2.py3-none-any.whl
Requirement already satisfied: Werkzeug>=0.14 in /usr/lib/python3.6/site-packages (from flask->-r requirements.txt (line 1)) (0.15.4)
Requirement already satisfied: click>=5.1 in /usr/lib/python3.6/site-packages (from flask->-r requirements.txt (line 1)) (7.0)
Requirement already satisfied: itsdangerous>=0.24 in /usr/lib/python3.6/site-packages (from flask->-r requirements.txt (line 1)) (1.1.0)
Requirement already satisfied: Jinja2>=2.10 in /usr/lib/python3.6/site-packages (from flask->-r requirements.txt (line 1)) (2.10.1)
Collecting aniso8601>=0.82 (from flask_restful->-r requirements.txt (line 2))
  Downloading https://files.pythonhosted.org/packages/45/a4/b4fcadbdab46c2ec2d2f6f8b4ab3f64fd0040789ac7f065eba82119cd602/aniso8601-7.0.0-py2.py3-none-any.whl (42kB)
     |████████████████████████████████| 51kB 6.7MB/s 
Collecting six>=1.3.0 (from flask_restful->-r requirements.txt (line 2))
  Downloading https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl
Collecting pytz (from flask_restful->-r requirements.txt (line 2))
  Downloading https://files.pythonhosted.org/packages/3d/73/fe30c2daaaa0713420d0382b16fbb761409f532c56bdcc514bf7b6262bb6/pytz-2019.1-py2.py3-none-any.whl (510kB)
     |████████████████████████████████| 512kB 394kB/s 
Requirement already satisfied: MarkupSafe>=0.23 in /usr/lib/python3.6/site-packages (from Jinja2>=2.10->flask->-r requirements.txt (line 1)) (1.1.1)
Installing collected packages: aniso8601, six, pytz, flask-restful
Successfully installed aniso8601-7.0.0 flask-restful-0.3.7 pytz-2019.1 six-1.12.0
/app # 

 Entonces a nuestro archivo requirements.txt le agregamos la linea flask_restful, rehabilitamos las lineas ENTRYPOINT en Dockerfile y contruimos nuevamente la imagen, para posteriormente ejecutarla.

(venv) bext@bext-VPCF13WFX:~/workspace/flask-crud-rest-app$ nano requirements.txt
(venv) bext@bext-VPCF13WFX:~/workspace/flask-crud-rest-app$ nano Dockerfile
(venv) bext@bext-VPCF13WFX:~/workspace/flask-crud-rest-app$ docker build -t flaskapp:latest .
Sending build context to Docker daemon  36.62MB
Step 1/8 : FROM alpine:latest
 ---> 055936d39205
Step 2/8 : RUN apk add --no-cache python3-dev     && pip3 install --upgrade pip
 ---> Using cache
 ---> d0bc58770e6e
Step 3/8 : WORKDIR /app
 ---> Using cache
 ---> 68ff8f17bb98
Step 4/8 : COPY . /app
 ---> 80fa082ead42
Step 5/8 : RUN pip3 --no-cache-dir install -r requirements.txt
 ---> Running in 30f322fc6f39
Collecting flask (from -r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/9a/74/670ae9737d14114753b8c8fdf2e8bd212a05d3b361ab15b44937dfd40985/Flask-1.0.3-py2.py3-none-any.whl (92kB)
Collecting flask_restful (from -r requirements.txt (line 2))
  Downloading https://files.pythonhosted.org/packages/17/44/6e490150ee443ca81d5f88b61bb4bbb133d44d75b0b716ebe92489508da4/Flask_RESTful-0.3.7-py2.py3-none-any.whl
Collecting Jinja2>=2.10 (from flask->-r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/1d/e7/fd8b501e7a6dfe492a433deb7b9d833d39ca74916fa8bc63dd1a4947a671/Jinja2-2.10.1-py2.py3-none-any.whl (124kB)
Collecting click>=5.1 (from flask->-r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/fa/37/45185cb5abbc30d7257104c434fe0b07e5a195a6847506c074527aa599ec/Click-7.0-py2.py3-none-any.whl (81kB)
Collecting Werkzeug>=0.14 (from flask->-r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/9f/57/92a497e38161ce40606c27a86759c6b92dd34fcdb33f64171ec559257c02/Werkzeug-0.15.4-py2.py3-none-any.whl (327kB)
Collecting itsdangerous>=0.24 (from flask->-r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/76/ae/44b03b253d6fade317f32c24d100b3b35c2239807046a4c953c7b89fa49e/itsdangerous-1.1.0-py2.py3-none-any.whl
Collecting aniso8601>=0.82 (from flask_restful->-r requirements.txt (line 2))
  Downloading https://files.pythonhosted.org/packages/45/a4/b4fcadbdab46c2ec2d2f6f8b4ab3f64fd0040789ac7f065eba82119cd602/aniso8601-7.0.0-py2.py3-none-any.whl (42kB)
Collecting pytz (from flask_restful->-r requirements.txt (line 2))
  Downloading https://files.pythonhosted.org/packages/3d/73/fe30c2daaaa0713420d0382b16fbb761409f532c56bdcc514bf7b6262bb6/pytz-2019.1-py2.py3-none-any.whl (510kB)
Collecting six>=1.3.0 (from flask_restful->-r requirements.txt (line 2))
  Downloading https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl
Collecting MarkupSafe>=0.23 (from Jinja2>=2.10->flask->-r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/b9/2e/64db92e53b86efccfaea71321f597fa2e1b2bd3853d8ce658568f7a13094/MarkupSafe-1.1.1.tar.gz
Installing collected packages: MarkupSafe, Jinja2, click, Werkzeug, itsdangerous, flask, aniso8601, pytz, six, flask-restful
  Running setup.py install for MarkupSafe: started
    Running setup.py install for MarkupSafe: finished with status 'done'
Successfully installed Jinja2-2.10.1 MarkupSafe-1.1.1 Werkzeug-0.15.4 aniso8601-7.0.0 click-7.0 flask-1.0.3 flask-restful-0.3.7 itsdangerous-1.1.0 pytz-2019.1 six-1.12.0
Removing intermediate container 30f322fc6f39
 ---> 8ef2dc85cff7
Step 6/8 : EXPOSE 5000
 ---> Running in 0692890f6a16
Removing intermediate container 0692890f6a16
 ---> 17b16328871c
Step 7/8 : ENTRYPOINT ["python3"]
 ---> Running in cd2b280a590b
Removing intermediate container cd2b280a590b
 ---> ef6538099f56
Step 8/8 : CMD ["app.py"]
 ---> Running in c9ea84a94729
Removing intermediate container c9ea84a94729
 ---> 34a2b83e9c1a
Successfully built 34a2b83e9c1a
Successfully tagged flaskapp:latest
(venv) bext@bext-VPCF13WFX:~/workspace/flask-crud-rest-app$ docker run -it flaskapp 
DEBUG:root:Arrancando la aplicacion
 * Serving Flask app "app" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
INFO:werkzeug: * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
INFO:werkzeug: * Restarting with stat
DEBUG:root:Arrancando la aplicacion
WARNING:werkzeug: * Debugger is active!
INFO:werkzeug: * Debugger PIN: 103-363-790

OK, listo, ahora ya incluyo el paquete y se ejecuto.

(venv) bext@bext-VPCF13WFX:~/DockerAppConfig/DockerSampleApp$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
84ce5734217c        flaskapp            "python3 app.py"    About a minute ago   Up About a minute   5000/tcp            elated_carson

flaskapp esta corriendo en el puerto 5000 pero no hay respuesta en el postman


 Esto es porque aún tenemos que especificar en el comando de linea docker run
el mapeo de puerto con el parametro -p 5000:5000, diciendole que el puerto del contenedor 5000 correspondera al 5000

(venv) bext@bext-VPCF13WFX:~/workspace/flask-crud-rest-app$ docker run -it -p 5000:5000 flaskapp 
DEBUG:root:Arrancando la aplicacion
 * Serving Flask app "app" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
INFO:werkzeug: * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
INFO:werkzeug: * Restarting with stat
DEBUG:root:Arrancando la aplicacion
WARNING:werkzeug: * Debugger is active!
INFO:werkzeug: * Debugger PIN: 103-363-790
DEBUG:root:EN post method por task by id. taskId = 444
INFO:werkzeug:172.17.0.1 - - [19/Jun/2019 21:08:42] "POST /api/v1.0/task/Id/444 HTTP/1.1" 200 -

 Ya se observa el request que se hizo posteriormente en postman.


Ok.


eot

No hay comentarios:

Publicar un comentario