<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="es">
		<id>https://1984.lsi.us.es/wiki-egc/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Sergardom</id>
		<title>Wiki de EGC - Contribuciones del usuario [es]</title>
		<link rel="self" type="application/atom+xml" href="https://1984.lsi.us.es/wiki-egc/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Sergardom"/>
		<link rel="alternate" type="text/html" href="https://1984.lsi.us.es/wiki-egc/index.php/Especial:Contribuciones/Sergardom"/>
		<updated>2026-05-14T10:35:27Z</updated>
		<subtitle>Contribuciones del usuario</subtitle>
		<generator>MediaWiki 1.29.0</generator>

	<entry>
		<id>https://1984.lsi.us.es/wiki-egc/index.php?title=Creando_mi_propia_imagen_para_python&amp;diff=8105</id>
		<title>Creando mi propia imagen para python</title>
		<link rel="alternate" type="text/html" href="https://1984.lsi.us.es/wiki-egc/index.php?title=Creando_mi_propia_imagen_para_python&amp;diff=8105"/>
				<updated>2019-10-07T14:58:38Z</updated>
		
		<summary type="html">&lt;p&gt;Sergardom: /* Creando una imagen para una app Flask en python */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Podemos modificar una imagen existente y guardarla con un nombre diferente:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;&lt;br /&gt;
# docker run -it ubuntu bash&lt;br /&gt;
root@d66f7a3268e6:/# &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Fijaros en que el prompt del interprete de ordenes ha cambiado e indica el numero que identifica de manera unica al contenedor que hemos lanzado. Este numero cambia para cada nueva instancia que lanzamos.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;&lt;br /&gt;
root@d66f7a3268e6:/# apt-get update&lt;br /&gt;
root@d66f7a3268e6:/# apt-get install apache2&lt;br /&gt;
apt-get install apache2&lt;br /&gt;
Reading package lists... Done&lt;br /&gt;
Building dependency tree       &lt;br /&gt;
Reading state information... Done&lt;br /&gt;
The following additional packages will be installed:&lt;br /&gt;
  apache2-bin apache2-data apache2-utils ...&lt;br /&gt;
The following NEW packages will be installed:&lt;br /&gt;
  apache2 apache2-bin apache2-data apache2-utils ...&lt;br /&gt;
0 upgraded, 57 newly installed, 0 to remove and 4 not upgraded.&lt;br /&gt;
Need to get 22.6 MB/22.6 MB of archives.&lt;br /&gt;
After this operation, 102 MB of additional disk space will be used.&lt;br /&gt;
Do you want to continue? [Y/n] &lt;br /&gt;
...&lt;br /&gt;
root@d66f7a3268e6:/# &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Escribo 'Y' y pulso enter para comenzar la instalacion del servidor web apache2.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;&lt;br /&gt;
root@d66f7a3268e6:/# exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;&lt;br /&gt;
# docker commit -m &amp;quot;Imagen de ubuntu con apache2&amp;quot; -a &amp;quot;profe&amp;quot; d66f7a3268e6 ubuntu/apache2&lt;br /&gt;
sha256:b68ef77405104a6ea2de6fde986a519a2fc9710b26d9ae8ec2553f5050c51fd3&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;&lt;br /&gt;
# docker images&lt;br /&gt;
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE&lt;br /&gt;
ubuntu/apache2      latest              b68ef7740510        36 seconds ago      260MB&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;&lt;br /&gt;
# docker run -it -p 8888:80 ubuntu/apache2&lt;br /&gt;
# service apache2 start&lt;br /&gt;
 * Starting Apache httpd web server apache2                                     AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message&lt;br /&gt;
 * &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Y ahora si abro un navegador web al localhost al puerto 8888, me aparece la pagina que indica que apache esta funcionando correctamente.&lt;br /&gt;
&lt;br /&gt;
= Creando una imagen para una app Flask en python =&lt;br /&gt;
&lt;br /&gt;
*Todo el código fuente está disponible en : https://github.com/EGCETSII/1920-Practica-1&lt;br /&gt;
&lt;br /&gt;
Comenzamos creando nuestra app.&lt;br /&gt;
File holamundo.py&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from flask import Flask  &lt;br /&gt;
app = Flask(__name__) &lt;br /&gt;
@app.route('/') &lt;br /&gt;
def hello_world():     &lt;br /&gt;
    return 'Hello World' &lt;br /&gt;
@app.route('/hello/&amp;lt;name&amp;gt;')&lt;br /&gt;
def hello_name(name):&lt;br /&gt;
    return 'Hello %s!' % name&lt;br /&gt;
if __name__ == '__main__':      &lt;br /&gt;
    app.run()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Definimos las dependencias&lt;br /&gt;
File requirements.txt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
Flask&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Podemos usar la imagen de python3 existente en los repositorios de docker, y modificar anadiendo en la carpeta apps la aplicacion que hemos desarrollado&lt;br /&gt;
&lt;br /&gt;
Para ello podemos crear un fichero Dockerfile que nos automatiza la creacion de una imagen modificada:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;&lt;br /&gt;
# Base image &lt;br /&gt;
FROM python:3 &lt;br /&gt;
#copy the requirements txt file with all our dependencies&lt;br /&gt;
COPY requirements.txt ./ &lt;br /&gt;
#install the dependencies&lt;br /&gt;
RUN pip install --no-cache-dir -r requirements.txt  &lt;br /&gt;
#copy the app in the image&lt;br /&gt;
COPY holamundo.py ./  &lt;br /&gt;
#define a default command to execute&lt;br /&gt;
CMD [ &amp;quot;python&amp;quot;, &amp;quot;./holamundo.py&amp;quot; ]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Este fichero indica que docker tiene que descargar la imagen python en su tercera versión y tiene que añadir el fichero requirements a la carpeta de usuario de la imagen.&lt;br /&gt;
&lt;br /&gt;
Docker nos ofrece un lenguaje de scripting para automatizar la creacion de imagenes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;&lt;br /&gt;
# docker build -t holamundo-flask .&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Va a crear la imagen, tras esto podemos lanzar:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;&lt;br /&gt;
# docker run -it -p 5000:5000 holamundo-flask&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Tras esto, desde un navegador, abrimos la URI: http://localhost:5000/hello/&amp;quot;yourname&amp;quot;&lt;/div&gt;</summary>
		<author><name>Sergardom</name></author>	</entry>

	<entry>
		<id>https://1984.lsi.us.es/wiki-egc/index.php?title=Creando_mi_propia_imagen_para_python&amp;diff=8104</id>
		<title>Creando mi propia imagen para python</title>
		<link rel="alternate" type="text/html" href="https://1984.lsi.us.es/wiki-egc/index.php?title=Creando_mi_propia_imagen_para_python&amp;diff=8104"/>
				<updated>2019-10-07T14:58:00Z</updated>
		
		<summary type="html">&lt;p&gt;Sergardom: /* Creando una imagen para una app Flask en python */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Podemos modificar una imagen existente y guardarla con un nombre diferente:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;&lt;br /&gt;
# docker run -it ubuntu bash&lt;br /&gt;
root@d66f7a3268e6:/# &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Fijaros en que el prompt del interprete de ordenes ha cambiado e indica el numero que identifica de manera unica al contenedor que hemos lanzado. Este numero cambia para cada nueva instancia que lanzamos.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;&lt;br /&gt;
root@d66f7a3268e6:/# apt-get update&lt;br /&gt;
root@d66f7a3268e6:/# apt-get install apache2&lt;br /&gt;
apt-get install apache2&lt;br /&gt;
Reading package lists... Done&lt;br /&gt;
Building dependency tree       &lt;br /&gt;
Reading state information... Done&lt;br /&gt;
The following additional packages will be installed:&lt;br /&gt;
  apache2-bin apache2-data apache2-utils ...&lt;br /&gt;
The following NEW packages will be installed:&lt;br /&gt;
  apache2 apache2-bin apache2-data apache2-utils ...&lt;br /&gt;
0 upgraded, 57 newly installed, 0 to remove and 4 not upgraded.&lt;br /&gt;
Need to get 22.6 MB/22.6 MB of archives.&lt;br /&gt;
After this operation, 102 MB of additional disk space will be used.&lt;br /&gt;
Do you want to continue? [Y/n] &lt;br /&gt;
...&lt;br /&gt;
root@d66f7a3268e6:/# &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Escribo 'Y' y pulso enter para comenzar la instalacion del servidor web apache2.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;&lt;br /&gt;
root@d66f7a3268e6:/# exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;&lt;br /&gt;
# docker commit -m &amp;quot;Imagen de ubuntu con apache2&amp;quot; -a &amp;quot;profe&amp;quot; d66f7a3268e6 ubuntu/apache2&lt;br /&gt;
sha256:b68ef77405104a6ea2de6fde986a519a2fc9710b26d9ae8ec2553f5050c51fd3&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;&lt;br /&gt;
# docker images&lt;br /&gt;
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE&lt;br /&gt;
ubuntu/apache2      latest              b68ef7740510        36 seconds ago      260MB&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;&lt;br /&gt;
# docker run -it -p 8888:80 ubuntu/apache2&lt;br /&gt;
# service apache2 start&lt;br /&gt;
 * Starting Apache httpd web server apache2                                     AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message&lt;br /&gt;
 * &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Y ahora si abro un navegador web al localhost al puerto 8888, me aparece la pagina que indica que apache esta funcionando correctamente.&lt;br /&gt;
&lt;br /&gt;
= Creando una imagen para una app Flask en python =&lt;br /&gt;
&lt;br /&gt;
*Todo el código fuente está disponible en : https://github.com/EGCETSII/1920-Practica-1 *&lt;br /&gt;
&lt;br /&gt;
Comenzamos creando nuestra app.&lt;br /&gt;
File holamundo.py&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from flask import Flask  &lt;br /&gt;
app = Flask(__name__) &lt;br /&gt;
@app.route('/') &lt;br /&gt;
def hello_world():     &lt;br /&gt;
    return 'Hello World' &lt;br /&gt;
@app.route('/hello/&amp;lt;name&amp;gt;')&lt;br /&gt;
def hello_name(name):&lt;br /&gt;
    return 'Hello %s!' % name&lt;br /&gt;
if __name__ == '__main__':      &lt;br /&gt;
    app.run()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Definimos las dependencias&lt;br /&gt;
File requirements.txt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
Flask&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Podemos usar la imagen de python3 existente en los repositorios de docker, y modificar anadiendo en la carpeta apps la aplicacion que hemos desarrollado&lt;br /&gt;
&lt;br /&gt;
Para ello podemos crear un fichero Dockerfile que nos automatiza la creacion de una imagen modificada:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;&lt;br /&gt;
# Base image &lt;br /&gt;
FROM python:3 &lt;br /&gt;
#copy the requirements txt file with all our dependencies&lt;br /&gt;
COPY requirements.txt ./ &lt;br /&gt;
#install the dependencies&lt;br /&gt;
RUN pip install --no-cache-dir -r requirements.txt  &lt;br /&gt;
#copy the app in the image&lt;br /&gt;
COPY holamundo.py ./  &lt;br /&gt;
#define a default command to execute&lt;br /&gt;
CMD [ &amp;quot;python&amp;quot;, &amp;quot;./holamundo.py&amp;quot; ]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Este fichero indica que docker tiene que descargar la imagen python en su tercera versión y tiene que añadir el fichero requirements a la carpeta de usuario de la imagen.&lt;br /&gt;
&lt;br /&gt;
Docker nos ofrece un lenguaje de scripting para automatizar la creacion de imagenes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;&lt;br /&gt;
# docker build -t holamundo-flask .&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Va a crear la imagen, tras esto podemos lanzar:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;&lt;br /&gt;
# docker run -it -p 5000:5000 holamundo-flask&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Tras esto, desde un navegador, abrimos la URI: http://localhost:5000/hello/&amp;quot;yourname&amp;quot;&lt;/div&gt;</summary>
		<author><name>Sergardom</name></author>	</entry>

	</feed>