Correr una Aplicación Web en Docker


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

$ docker run -d -P training/webapp python

-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:>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 o localhost:49155

docker logs xyz
  * Running on
-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 #This would map port 5000 inside our container to port 80 on our local host. 

En el dockerfile, por ejemplo, incluimos

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

$ 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
$ docker port xyz
docker top xyz #examine the processes running inside container. We can see python
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


Leave a Reply

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

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>