Correr una Aplicación Web en Docker

Introducción

For our web application we’re going to run a Python Flask application.

$ docker run -d -P training/webapp python app.py

-P #map any required network ports inside our container to our host. This lets us view our web application.
training/webapp #pre-built image you’ve created that contains a simple Python Flask web application
See on browser
docker ps
  NAMES: xyz #id o name
  PORTS: 0.0.0.0:49155->5000/tcp #In this case Docker has exposed port 5000 (the default Python Flask port) on port 49155. Para ver la aplicación corriendo ir a un navegador y escribir http://0.0.0.0:49155 o localhost:49155


docker logs xyz
  * Running on http://0.0.0.0:5000/
-p flag
-p flag #is a shortcut for -p 5000 that maps port 5000 inside the container to a high port (from ephemeral port range which typically ranges from 32768 to 61000) on the local Docker host. 

$ docker run -d -p 80:5000 training/webapp python app.py #This would map port 5000 inside our container to port 80 on our local host. 
EXPOSE

En el dockerfile, por ejemplo, incluimos
EXPOSE 80
EXPOSE 443

Debemos usar alguno de los puertos expuestos
docker run -p xx:80
docker run -p xx:443

commands
$ docker port xyz 5000 #Shortcut to see ports  we specify the ID or name of our container and then the port for which we need the corresponding public-facing port
  0.0.0.0:49155
  
$ docker port xyz
  5000/tcp 0.0.0.0:49155
  
docker top xyz #examine the processes running inside container. We can see python app.py
docker inspect xyz #low-level dive into our Docker container
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' xyz #Show specific element
docker start xyz #Restart stopped container -> 1) docker stop xyz 2) docker start xyz
docker rm xyz #Remove container -> 1) docker stop xyz 2) docker rm xyz

Fuente

https://docs.docker.com/engine/tutorials/usingdocker/

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *