2.5. Utilización de las imágenes UBI init
Este procedimiento muestra cómo construir un contenedor usando un Dockerfile que instala y configura un servidor web (httpd) para que se inicie automáticamente por el servicio systemd (/sbin/init) cuando el contenedor se ejecuta en un sistema anfitrión.
Procedimiento
Cree un Dockerfile con el siguiente contenido en un nuevo directorio:
FROM registry.access.redhat.com/ubi8/ubi-init RUN yum -y install httpd; yum clean all; systemctl enable httpd; RUN echo "Successful Web Server Test" > /var/www/html/index.html RUN mkdir /etc/systemd/system/httpd.service.d/; echo -e '[Service]\nRestart=always' > /etc/systemd/system/httpd.service.d/httpd.conf EXPOSE 80 CMD [ "/sbin/init" ]El Dockerfile instala el paquete
httpd, habilita el serviciohttpdpara que se inicie en el momento del arranque, crea un archivo de prueba (index.html), expone el servidor web al host (puerto 80), e inicia el servicio systemd init (/sbin/init) cuando se inicia el contenedor.Construye el contenedor:
# podman build --format=docker -t mysysd .Opcionalmente, si quieres ejecutar contenedores con systemd y SELinux está habilitado en tu sistema, debes establecer la variable booleana
container_manage_cgroup:# setsebool -P container_manage_cgroup 1Ejecute el contenedor llamado
mysysd_run:# podman run -d --name=mysysd_run -p 80:80 mysysdLa imagen
mysysdse ejecuta como el contenedormysysd_runcomo un proceso demonio, con el puerto 80 del contenedor expuesto al puerto 80 en el sistema anfitrión.Comprueba que el contenedor está en marcha:
# podman ps a282b0c2ad3d localhost/mysysd:latest /sbin/init 15 seconds ago Up 14 seconds ago 0.0.0.0:80->80/tcp mysysd_runPrueba el servidor web:
# curl localhost/index.html Successful Web Server Test