Red Hat Training
A Red Hat training course is available for RHEL 8
4.5. Construindo uma imagem baseada na UBI
Você pode construir imagens de contêineres baseados no UBI da mesma forma que constrói outras imagens, com uma exceção. Você deve desativar todos os repositórios de yum não baseados no UBI quando você realmente construir as imagens, se você quiser ter certeza de que sua imagem contém apenas o software Red Hat que você pode redistribuir.
Aqui está um exemplo de criação de um container de servidor Web baseado no UBI a partir de um Dockerfile com o utilitário buildah
:
Para imagens de ubi8/ubi-minimal
, use microdnf
ao invés de yum
abaixo:
RUN microdnf update -y && rm -rf /var/cache/yum RUN microdnf install httpd -y && microdnf clean all
Create a Dockerfile: Adicione um
Dockerfile
com o seguinte conteúdo a um novo diretório:FROM registry.access.redhat.com/ubi8/ubi USER root LABEL maintainer="John Doe" # Update image RUN yum update --disablerepo=* --enablerepo=ubi-8-appstream --enablerepo=ubi-8-baseos -y && rm -rf /var/cache/yum RUN yum install --disablerepo=* --enablerepo=ubi-8-appstream --enablerepo=ubi-8-baseos httpd -y && rm -rf /var/cache/yum # Add default Web page and expose port RUN echo "The Web Server is Running" > /var/www/html/index.html EXPOSE 80 # Start the service CMD ["-D", "FOREGROUND"] ENTRYPOINT ["/usr/sbin/httpd"]
Build the new image: Enquanto estiver nesse diretório, use
buildah
para criar uma nova imagem em camadas da UBI:# buildah bud -t johndoe/webserver . STEP 1: FROM registry.access.redhat.com/ubi8/ubi:latest STEP 2: USER root STEP 3: LABEL maintainer="John Doe" STEP 4: RUN yum update --disablerepo=* --enablerepo=ubi-8-appstream --enablerepo=ubi-8-baseos -y . . . No packages marked for update STEP 5: RUN yum install --disablerepo=* --enablerepo=ubi-8-appstream --enablerepo=ubi-8-baseos httpd -y Loaded plugins: ovl, product-id, search-disabled-repos Resolving Dependencies --> Running transaction check ============================================================= Package Arch Version Repository Size ============================================================= Installing: httpd x86_64 2.4.37-10 latest-rhubi-8.0-appstream 1.4 M Installing dependencies: apr x86_64 1.6.3-9.el8 latest-rhubi-8.0-appstream 125 k apr-util x86_64 1.6.1-6.el8 latest-rhubi-8.0-appstream 105 k httpd-filesystem noarch 2.4.37-10 latest-rhubi-8.0-appstream 34 k httpd-tools x86_64 2.4.37-10. ... Transaction Summary ... Complete! STEP 6: RUN echo "The Web Server is Running" > /var/www/html/index.html STEP 7: EXPOSE 80 STEP 8: CMD ["-D", "FOREGROUND"] STEP 9: ENTRYPOINT ["/usr/sbin/httpd"] STEP 10: COMMIT ... Writing manifest to image destination Storing signatures --> 36a604cc0dd3657b46f8762d7ef69873f65e16343b54c63096e636c80f0d68c7
Test: Teste a imagem do servidor web em camadas da UBI:
# podman run -d -p 80:80 johndoe/webserver bbe98c71d18720d966e4567949888dc4fb86eec7d304e785d5177168a5965f64 # curl http://localhost/index.html The Web Server is Running