os01 - gpulido-redhat/workshopclaro Wiki

Introducción a Contenedores. (Teórico)

¿Qué son los contenedores?

Un contenedor​ es un recipiente de carga para el transporte marítimo o fluvial, transporte terrestre y transporte multimodal

Los contenedores en TI, son tecnologías que le permiten empaquetar y aislar las aplicaciones junto con todo el entorno de tiempo de ejecución, es decir, con todos los archivos que requieren para ejecutarse

Algunos repositorios donde podemos encontrar imagenes de contenedores son:

Maquinas Virtuales vs Contenedores

Beneficios:


Introducción a la gestión de contenedores con podman

Podman es una herramienta de código abierto, nativa de Linux sin demonios, diseñada para facilitar la búsqueda, ejecución, compilación, uso compartido e implementación de aplicaciones utilizando contenedores e imágenes de contenedor de la Iniciativa de Contenedores Abiertos (OCI).

Podman proporciona una interfaz de línea de comandos (CLI) familiar para cualquiera que haya utilizado Docker Container Engine. La mayoría de los usuarios pueden simplemente alias Docker a Podman (alias docker = podman) sin ningún problema.

Al igual que otros motores de contenedores comunes (Docker, CRI-O, containerd), Podman se basa en un Container Runtime compatible con OCI (runc, crun, runv, etc.) para interactuar con el sistema operativo y crear los contenedores en ejecución. Esto hace que los contenedores en ejecución creados por Podman sean casi indistinguibles de los creados por cualquier otro motor de contenedores común.


Administración de contenedores con Podman. (Demostración)

Gestión de contenedores con Podman

Pull

[[email protected] ~]# podman pull registry.access.redhat.com/ubi8:latest
Trying to pull registry.access.redhat.com/ubi8:latest...
Getting image source signatures
Copying blob 63f9f4c31162 done
Copying blob ce3c6836540f done
Copying config cc06568478 done
Writing manifest to image destination
Storing signatures
cc0656847854310306093b3dc1a7d9e7fc06399da46853e0c921cd5ec1906bfd

IMAGES

[[email protected] ~]# podman images
REPOSITORY                       TAG         IMAGE ID      CREATED      SIZE
registry.access.redhat.com/ubi8  latest      cc0656847854  4 weeks ago  235 MB

RUN

[[email protected] ~]# podman run --name rhel8 -it -d registry.access.redhat.com/ubi8:latest /bin/bash
527e97212a0fb8fbcdb4b0b622ea1b84f17949e88be3682c143a02e501db4f9a

PS

[[email protected] ~]# podman ps
CONTAINER ID  IMAGE                                   COMMAND    CREATED         STATUS             PORTS  NAMES
527e97212a0f  registry.access.redhat.com/ubi8:latest  /bin/bash  20 seconds ago  Up 20 seconds ago         rhel8

[[email protected] ~]# ps -aux | grep 527e97212a0f

STOP

[[email protected] ~]# podman stop rhel8
527e97212a0fb8fbcdb4b0b622ea1b84f17949e88be3682c143a02e501db4f9a

START

[[email protected] ~]# podman start rhel8
rhel8

RESTART

[[email protected] ~]# podman restart rhel8
527e97212a0fb8fbcdb4b0b622ea1b84f17949e88be3682c143a02e501db4f9a

PS -A

[[email protected] ~]# podman stop rhel8
527e97212a0fb8fbcdb4b0b622ea1b84f17949e88be3682c143a02e501db4f9a

[[email protected] ~]# podman ps
CONTAINER ID  IMAGE  COMMAND  CREATED  STATUS  PORTS  NAMES

[[email protected] ~]# podman ps -a
CONTAINER ID  IMAGE                                   COMMAND               CREATED             STATUS                    PORTS                                                                      NAMES
527e97212a0f  registry.access.redhat.com/ubi8:latest  /bin/bash             About a minute ago  Exited (0) 4 seconds ago                       

[[email protected] ~]# podman start rhel8
rhel8                                                      rhel8

[[email protected] ~]# podman ps
CONTAINER ID  IMAGE                                   COMMAND    CREATED        STATUS             PORTS  NAMES
527e97212a0f  registry.access.redhat.com/ubi8:latest  /bin/bash  2 minutes ago  Up 10 seconds ago         rhel8

EXEC

[[email protected] ~]# podman exec -it rhel8 /bin/bash

[[email protected] /]# exit
exit

[[email protected] ~]# podman exec -it -l /bin/bash

[[email protected] /]# exit
exit

Para depurar utilizar STOP y RM

[[email protected] ~]# podman stop rhel8
527e97212a0fb8fbcdb4b0b622ea1b84f17949e88be3682c143a02e501db4f9a

[[email protected] ~]# podman rm rhel8
527e97212a0fb8fbcdb4b0b622ea1b84f17949e88be3682c143a02e501db4f9a

[[email protected] ~]# podman ps

[[email protected] ~]# podman ps -a

RMI

[[email protected] ~]# podman rmi registry.access.redhat.com/ubi8:latest
Untagged: registry.access.redhat.com/ubi8:latest
Deleted: cc0656847854310306093b3dc1a7d9e7fc06399da46853e0c921cd5ec1906bfd

[[email protected] ~]# podman images

Si la imagen no se ha puleado inicialmente y se ejecutar un run este proceso la descarga

[[email protected] ~]# podman run --name rhel8 -it -d registry.access.redhat.com/ubi8:latest
Trying to pull registry.access.redhat.com/ubi8:latest...
Getting image source signatures
Copying blob 63f9f4c31162 done
Copying blob ce3c6836540f done
Copying config cc06568478 done
Writing manifest to image destination
Storing signatures
593fdfffa935ff7b014cec1e724b104900b5942f0fffb4559ba59a9817955bd5

[[email protected] ~]# podman images
REPOSITORY                        TAG      IMAGE ID       CREATED         SIZE
registry.access.redhat.com/ubi8   latest   cc0656847854   2 weeks ago     235 MB

Crear un objeto de tipo usuario, asignarle una contraseña y probar la efimeralidad

[[email protected] ~]# podman exec -it -l /bin/bash

[[email protected] /]# useradd user9
[[email protected] /]# passwd user9
Changing password for user user9.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.

[[email protected] /]# id user9
uid=1000(user9) gid=1000(user9) groups=1000(user9)

[[email protected] /]# cat /etc/passwd | grep user9
user9:x:1000:1000::/home/user9:/bin/bash

[[email protected] /]# cat /etc/shadow | grep user9
user9:$6$ZpD1cIjGEdfLDe5j$7W4PEpIP8ljIG7pbrhakMys4e8iDL1Hj7N/fQvyaLI1W1.cNJcwPKKDql1sgSuN4QqEbKaW4G.CBCoYwXuRAd0:18949:0:99999:7:::

[[email protected] /]# exit
exit

[[email protected] ~]# podman stop rhel8 ; podman rm rhel8
593fdfffa935ff7b014cec1e724b104900b5942f0fffb4559ba59a9817955bd5
593fdfffa935ff7b014cec1e724b104900b5942f0fffb4559ba59a9817955bd5

[[email protected] ~]# podman run --name rhel8 -it -d registry.access.redhat.com/ubi8:latest
50861d1d07cb6faa7ec68a6f274469680dfc50d7677ca3eb73992ae4580fdbd4

[[email protected] ~]# podman exec -l -it /bin/bash

[[email protected] /]# id user9
id: ‘user9’: no such user

[[email protected] /]# exit
exit

[[email protected] ~]# podman stop rhel8 ; podman rm rhel8
50861d1d07cb6faa7ec68a6f274469680dfc50d7677ca3eb73992ae4580fdbd4
50861d1d07cb6faa7ec68a6f274469680dfc50d7677ca3eb73992ae4580fdbd4

COMMIT

[[email protected] ~]# podman run --name rhel8 -it -d registry.access.redhat.com/ubi8:latest
ca0c15e06900db412c703ec0af252c551b4bb590df631c3b7d3e7434cd15e631

[[email protected] ~]# podman exec -l -it /bin/bash

[[email protected] /]# useradd user9

[[email protected] /]# echo "redhat" | passwd --stdin user9
Changing password for user user9.
passwd: all authentication tokens updated successfully.

[[email protected] /]# su - user9

[[email protected] ~]$ id
uid=1000(user9) gid=1000(user9) groups=1000(user9)

[[email protected] ~]$ exit
logout

[[email protected] /]# exit
exit

[[email protected] ~]# podman commit -q -a "Jaime Zamudio" rhel8 custom-rhel8

[[email protected] ~]# podman images
REPOSITORY                        TAG      IMAGE ID       CREATED              SIZE
localhost/custom-rhel8            latest   0759772b92eb   About a minute ago   235 MB
registry.access.redhat.com/ubi8   latest   cc0656847854   2 weeks ago          235 MB

[[email protected] ~]# podman stop rhel8 ; podman rm rhel8
ca0c15e06900db412c703ec0af252c551b4bb590df631c3b7d3e7434cd15e631
ca0c15e06900db412c703ec0af252c551b4bb590df631c3b7d3e7434cd15e631

[[email protected] ~]# podman run --name rhel8 -it -d localhost/custom-rhel8
ca3d137601cf6408394bbdc8c2f6350e615b1bb7c2a92920acdaafcc1d21c094

[[email protected] ~]# podman exec -it -l /bin/bash

[[email protected] /]# id user9
uid=1000(user9) gid=1000(user9) groups=1000(user9)

[[email protected] /]# grep ^user9 /etc/passwd
user9:x:1000:1000::/home/user9:/bin/bash

[[email protected]601cf /]# grep ^user9 /etc/shadow
user9:$6$V2Ht3.lE126nwzZx$DFPS/LGrxakLGye56RyhBrH05GTiCLItmfv3ZOLtgj1sVhe9imf/pQe.pHyMsPqUDZ4KQPS24t4Eazp8/Wq0s/:18949:0:99999:7:::

[[email protected] /]# exit
exit

TAG

[[email protected] ~]# podman ps

[[email protected] ~]# podman tag localhost/custom-rhel8:latest localhost/custom-rhel8:8.5

[[email protected] ~]# podman tag localhost/custom-rhel8:latest localhost/custom-rhel8:5

[[email protected] ~]# podman images
REPOSITORY                        TAG      IMAGE ID       CREATED              SIZE
localhost/custom-rhel8            5        be3485bdf603   About a minute ago   235 MB
localhost/custom-rhel8            latest   be3485bdf603   About a minute ago   235 MB
localhost/custom-rhel8            8.5      be3485bdf603   About a minute ago   235 MB
registry.access.redhat.com/ubi8   latest   cc0656847854   2 weeks ago          235 MB

[[email protected] ~]# podman rmi -f localhost/custom-rhel8:5
Untagged: localhost/custom-rhel8:5

[[email protected] ~]# podman images
REPOSITORY                        TAG      IMAGE ID       CREATED         SIZE
localhost/custom-rhel8            latest   be3485bdf603   3 minutes ago   235 MB
localhost/custom-rhel8            8.5      be3485bdf603   3 minutes ago   235 MB
registry.access.redhat.com/ubi8   latest   cc0656847854   2 weeks ago     235 MB

[[email protected] ~]# podman run --name rhel85 -it -d localhost/custom-rhel8:8.5
0f0e0c4760036871671eaeb2dfef03eef64a2d787d208df2829b4d32cf8be375

[[email protected] ~]# podman exec -it rhel85 /bin/bash

[[email protected] /]# id user9
uid=1000(user9) gid=1000(user9) groups=1000(user9)

[[email protected] /]# exit
exit

[[email protected] ~]# podman stop rhel8 rhel85
0f0e0c4760036871671eaeb2dfef03eef64a2d787d208df2829b4d32cf8be375
ca3d137601cf6408394bbdc8c2f6350e615b1bb7c2a92920acdaafcc1d21c094

[[email protected] ~]# podman rm rhel8 rhel85
ca3d137601cf6408394bbdc8c2f6350e615b1bb7c2a92920acdaafcc1d21c094
0f0e0c4760036871671eaeb2dfef03eef64a2d787d208df2829b4d32cf8be375

SAVE

[[email protected] ~]# podman images

[[email protected] ~]# podman save -q -o ~/custom-rhel8-latest.tar localhost/custom-rhel8:latest
Getting image source signatures
Copying blob 0d3f22d60daf done
Copying blob 0488bd866f64 done
Copying blob 431250c3978c done
Copying config be3485bdf6 done
Writing manifest to image destination
Storing signatures

[[email protected] ~]# podman save -q -o ~/custom-rhel8-latest-85.tar localhost/custom-rhel8:8.5
Getting image source signatures
Copying blob 0d3f22d60daf done
Copying blob 0488bd866f64 done
Copying blob 431250c3978c done
Copying config be3485bdf6 done
Writing manifest to image destination
Storing signatures

[[email protected] ~]# du -sh custom-rhel8-latest.tar custom-rhel8-latest-85.tar
225M    custom-rhel8-latest.tar
225M    custom-rhel8-latest-85.tar

[[email protected] ~]# tar -tf custom-rhel8-latest.tar
[[email protected] ~]# tar -tf custom-rhel8-latest-85.tar

[[email protected] ~]# podman rmi localhost/custom-rhel8:latest
Untagged: localhost/custom-rhel8:latest

[[email protected] ~]# podman rmi localhost/custom-rhel8:8.5
Untagged: localhost/custom-rhel8:8.5
Deleted: be3485bdf6039f8667428656b9ba2923c6e2811ad12b4039907d832c5bd0c46f

[[email protected] ~]# images

LOAD

[[email protected] ~]# podman load -i ~/custom-rhel8-latest.tar
Getting image source signatures
Copying blob 431250c3978c done
Copying blob 0d3f22d60daf skipped: already exists
Copying blob 0488bd866f64 skipped: already exists
Copying config be3485bdf6 done
Writing manifest to image destination
Storing signatures
Loaded image(s): localhost/custom-rhel8:latest

[[email protected] ~]# podman load -i ~/custom-rhel8-latest-85.tar
Getting image source signatures
Copying blob 431250c3978c skipped: already exists
Copying blob 0d3f22d60daf [--------------------------------------] 0.0b / 0.0b
Copying blob 0488bd866f64 [--------------------------------------] 0.0b / 0.0b
Copying config be3485bdf6 done
Writing manifest to image destination
Storing signatures
Loaded image(s): localhost/custom-rhel8:8.5

[[email protected] ~]# podman images
REPOSITORY                       TAG         IMAGE ID      CREATED         SIZE
localhost/custom-rhel8           8.5         4f03b3f031e2  10 minutes ago  235 MB
localhost/custom-rhel8           latest      4f03b3f031e2  10 minutes ago  235 MB
registry.access.redhat.com/ubi8  latest      cc0656847854  4 weeks ago     235 MB

[[email protected] ~]# podman run --name rhel8 -it -d localhost/custom-rhel8

EXPORT

[[email protected] ~]# podman ps

[[email protected] ~]# podman export -o ~/custom-rhel8-export.tar rhel8

IMPORT

[[email protected] ~]# podman import ~/custom-rhel8-export.tar localhost/custom-rhel8-export

[[email protected] ~]# podman rmi localhost/custom-rhel8-export

INSPECT

[[email protected] ~]# podman inspect rhel8

HISTORY

[[email protected] ~]# podman history localhost/custom-rhel8:latest
ID            CREATED         CREATED BY  SIZE        COMMENT
4f03b3f031e2  20 minutes ago  /bin/sh     317 kB      FROM registry.access.redhat.com/ubi8:latest
cc0656847854  4 weeks ago                 20.5 kB
<missing>     4 weeks ago                 235 MB      Imported from -

STAT

[[email protected] ~]# podman stats rhel8

ID             NAME    CPU %   MEM USAGE / LIMIT   MEM %   NET IO              BLOCK IO            PIDS
6bc4d894b63f   rhel8   --      2.92MB / 16.62GB    0.02%   1.048kB / 4.252kB   8.192kB / 4.096kB   1

TOP

[[email protected] ~]# podman top rhel8
USER   PID   PPID   %CPU    ELAPSED          TTY     TIME   COMMAND
root   1     0      0.000   13m2.41896166s   pts/0   0s     /bin/bash

LOGS

[[email protected] ~]# podman logs rhel8

EVENTS

[[email protected] ~]# podman events --since 30m

PAUSE

[[email protected] ~]# podman pause rhel8
6bc4d894b63f925f2b2105bf98bf34698b4042572453825df448a70a38d46dd1

[[email protected] ~]# podman ps -a
CONTAINER ID  IMAGE                              COMMAND               CREATED         STATUS                   PORTS                                                                      NAMES
6bc4d894b63f  localhost/custom-rhel8:latest      /bin/bash             15 minutes ago  Paused      

UNPAUSE

[[email protected] ~]# podman unpause rhel8
6bc4d894b63f925f2b2105bf98bf34698b4042572453825df448a70a38d46dd1

INFO

[[email protected] ~]# podman info

VERSION

[[email protected] ~]# podman version
  1. Ejecutar un contenedor httpd como root y analizar
# podman login registry.redhat.io
# username: <user>
# password: <pass>
# podman run --name httpd-root -p 80:8080 -p 443:8443 -d registry.redhat.io/rhel8/httpd-24
# podman port -l
# podman inspect httpd-root | grep -E '(IPAddress|expose)'
# curl -si http://localhost | grep Test
# curl -si -k https://localhost | grep Test
# curl -si http://<container_ip>:8080 | grep Test
# curl -si -k https://<container_ip>:8443 | grep Test

Dentro de la conexión vnc abrir un terminal o navegador y acceder

# firefox http://<hostname>
# firefox https://<hostname>
  1. Ejecutar un contenedor httpd como developer y analizar
$ podman login registry.redhat.io
$ username: <user>
$ password: <pass>
$ podman run --name httpd-dev -p 8080 -p 8443 -d registry.redhat.io/rhel8/httpd-24
$ podman port -l
$ sudo netstat -taunlp | grep -E '(LISTEN|slirp4netns)'
$ curl -si http://localhost:<port_number> | grep Test
$ curl -si -k https://localhost:<port_number> | grep Test
$ firefox http://localhost:<port_number>
$ firefox https://localhost:<port_number>
  1. Ejecutar un contenedor httpd como developer y personalizarlo.
[[email protected] ~]$ podman pull rhscl/httpd-24-rhel7
[[email protected] ~]$ podman run --name httpd-server -p 8080 -p 8443 -d rhscl/httpd-24-rhel7
[[email protected] ~]$ podman exec -it httpd-server /bin/bash
[[email protected] ~]$ echo "TEST HTTPD SERVER FROM CONTAINERS" > /var/www/html/index.html
[[email protected] ~]$ exit
[[email protected] ~]$ podman inspect httpd-server | grep -E '(IPAddress|expose)'
[[email protected] ~]$ podman port -l
[[email protected] ~]$ curl -si http://localhost:<port_number>
[[email protected] ~]$ curl -si -k https://localhost:<port_number>
[[email protected] ~]$ podman exec -it httpd-server cat /var/www/html/index.html
[[email protected] ~]$ podman exec -it httpd-server /bin/bash -c 'echo "JAIME ZAMUDIO" >> /var/www/html/index.html'
[[email protected] ~]$ podman exec -it httpd-server cat /var/www/html/index.html
[[email protected] ~]$ curl -si http://localhost:<port_number>
[[email protected] ~]$ curl -si -k https://localhost:<port_number>
[[email protected] ~]$ podman kill -s SIGKILL httpd-server
[[email protected] ~]$ podman restart  httpd-server
[[email protected] ~]$ podman ps
[[email protected] ~]$ podman inspect httpd-server | grep -E '(IPAddress|expose)'
[[email protected] ~]$ curl -si http://localhost:<port_number>
[[email protected] ~]$ curl -si -k https://localhost:<port_number>
[[email protected] ~]$ podman commit httpd-server custom-httpd-server
[[email protected] ~]$ podman save > custom-httpd-server.tar custom-httpd-server
[[email protected] ~]$ du -sh ~/custom-httpd-server.tar
[[email protected] ~]$ tar -tf ~/custom-httpd-server.tar
[[email protected] ~]$ podman stop -a
[[email protected] ~]$ podman rm -a 
[[email protected] ~]$ podman rmi -a
[[email protected] ~]$ podman images
[[email protected] ~]$ podman load -i ~/custom-httpd-server.tar
[[email protected] ~]$ podman images
[[email protected] ~]$ podman tag localhost/custom-httpd-server:latest localhost/custom-httpd-server:2.0
[[email protected] ~]$ podman run --name custom-httpd-server-2 -p 8080 -p 8443 -d localhost/custom-httpd-server:2.0
[[email protected] ~]$ podman port -l
[[email protected] ~]$ curl -si http://localhost:<port_number>
[[email protected] ~]$ curl -si -k https://localhost:<port_number>

Opcional Pusharlo a Quay NOTA: Si sale error revisar en quay.io si se crea la carpeta si se crea como privada hacerla publica, sino se crea crearla como publica

[[email protected] ~]$ podman tag localhost/custom-httpd-server:2.0 quay.io/jaimemarianoz/custom-httpd-server:2.0
[[email protected] ~]$ podman login quay.io
[[email protected] ~]$ username: <user>
[[email protected] ~]$ password: <pass>
[[email protected] ~]$ podman push quay.io/jaimemarianoz/custom-httpd-server:2.0 # < Si falla revisar en la web de quay.io que el repositorio este como publico
[[email protected] ~]$ podman push quay.io/jaimemarianoz/custom-httpd-server:2.0
[[email protected] ~]$ podman stop -a
[[email protected] ~]$ podman rm -a
[[email protected] ~]$ podman rmi -af
[[email protected] ~]$ podman run --name custom-httpd-server -p 8080 -p 8443 -d quay.io/jaimemarianoz/custom-httpd-server:2.0
[[email protected] ~]$ podman port -l
[[email protected] ~]$ curl -si http://localhost:<port_number>
[[email protected] ~]$ curl -si -k https://localhost:<port_number>
  1. Ejecutar un contenedor mysql con contenido efímero.
[[email protected] ~]$ podman run --name mysql-server \
-e MYSQL_USER=user9 -e MYSQL_PASSWORD=redhat \
-e MYSQL_DATABASE=samples -e MYSQL_ROOT_PASSWORD=Password$ \
-d registry.access.redhat.com/rhscl/mysql-57-rhel7
[[email protected] ~]$ podman ps
[[email protected] ~]$ podman exec -it mysql-server /bin/bash

bash-4.2$ env | grep ^MYSQL_
bash-4.2$ mysql -u$MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DATABASE
mysql> show databases;
mysql> exit
bash-4.2$ exit

[developer[email protected] ~]$ wget ftp://classroom.opennova.pe/openshift/podman/samples.sql
[[email protected] ~]$ podman cp ~/sample.sql mysql-server:/tmp
[[email protected] ~]$ podman exec -it -l /bin/bash

bash-4.2$ mysql -uuser9 -predhat samples < /tmp/samples.sql
bash-4.2$ mysql -uuser9 -predhat samples
mysql> show databases;
mysql> describe Items;
mysql> select id,name,code from Items;
mysql> exit
bash-4.2$ exit

Para depurar todo ejecutar

[[email protected] ~]$ podman stop -a ; podman rm -a ; podman rmi -af
  1. Ejecutar un contenedor mysql con contenido persistente.
[[email protected] ~]$ mkdir -pv ~/mysql/data
[[email protected] ~]$ sudo semanage fcontext -a -t container_file_t '/home/developer/mysql/data'
[[email protected] ~]$ restorecon -RFvv /home/developer/mysql/data/
Relabeled /home/developer/mysql/data from unconfined_u:object_r:user_home_t:s0 to system_u:object_r:container_file_t:s0

[[email protected] ~]$ ls -ldZ ~/mysql/data/
drwxrwxr-x. 2 developer developer system_u:object_r:container_file_t:s0 6 Dec  1 22:20 /home/developer/mysql/data/

[[email protected] ~]$ podman unshare chown 27:27 ~/mysql/data

[[email protected] ~]$  podman run --name mysql-server-persistent \
-p 13306:3306 \
-v /home/developer/mysql/data:/var/lib/mysql \
-e MYSQL_USER=user9 -e MYSQL_PASSWORD=redhat -e MYSQL_DATABASE=samples -e MYSQL_ROOT_PASSWORD=Password$ \
-d registry.access.redhat.com/rhscl/mysql-57-rhel7

[[email protected] ~]$ podman ps
[[email protected] ~]$ podman exec -it mysql-server-persistent /bin/bash

bash-4.2$ env | grep ^MYSQL_
bash-4.2$ mysql -u$MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DATABASE
mysql> show databases;
mysql> exit
bash-4.2$ exit

[[email protected] ~]$ wget ftp://classroom.opennova.pe/openshift/podman/samples.sql
[[email protected] ~]$ netstat -taunlp | grep 13306
[[email protected] ~]$ sudo yum install -y mysql
[[email protected] ~]$ mysql -uuser9 -predhat -h127.0.0.1 -P 13306 samples < ~/samples.sql
[[email protected] ~]$ mysql -uuser9 -predhat -h127.0.0.1 -P 13306 samples -e "use samples; select * from Items;"
[[email protected] ~]$ podman unshare ls -l /home/developer/mysql/data/data/samples

[[email protected] ~]$ podman stop mysql-server-persistent
[[email protected] ~]$ podman rm mysql-server-persistent
[[email protected] ~]$ podman unshare ls -l /home/developer/mysql/data/data/samples

[[email protected] ~]$ podman run --name mysql-server-persistent \
-p 13306:3306 \
-v /home/developer/mysql/data:/var/lib/mysql \
-e MYSQL_USER=user9 -e MYSQL_PASSWORD=redhat -e MYSQL_DATABASE=samples -e MYSQL_ROOT_PASSWORD=Password$ \
-d registry.access.redhat.com/rhscl/mysql-57-rhel7

[[email protected] ~]$ mysql -uuser9 -predhat -h127.0.0.1 -P 13306 samples -e "use samples; select * from Items;"

Para depurar todo ejecutar

[[email protected] ~]$ podman stop -a ; podman rm -a ; podman rmi -af
[[email protected] ~]$ sudo rm -rf ~/mysql
  1. Construir una imagen de contenedor para httpd utilizando un Containerfile.
[[email protected] ~]$ mkdir custom-apache ; cd custom-apache
[[email protected] ~]$ wget ftp://classroom.opennova.pe/openshift/podman/Containerfile
[[email protected] custom-apache]$ mkdir src ; cd src
[[email protected] src]$ git clone https://github.com/workshopopennova/global.git
[[email protected] src]$ cd ~/custom-apache
[[email protected] src]$ podman build --layers=false -t custom-apache .
[[email protected] src]$ podman images
[[email protected] custom-apache]$ podman run --name custom-apache -d -p 8080:8080 custom-apache
[[email protected] custom-apache]$
[[email protected] custom-httpd]$ curl -si http://localhost:8080 | head -n 20
[[email protected] custom-httpd]$ firefox http://localhost:8080

Laboratorio: Containers with Podman

NOTA:

Requerimientos: 1. Implementar un contenedor de sistema operativo rhel8 con la siguiente información:

2. Implementar un contendor httpd con la siguiente información:

3. Implementar un contenedor mysql efímero con la siguiente información:

4. Implementar un contenedor mysql persistente con la siguiente información:

5. Construir una imagen de contenedor con la siguiente información: