可用于应用程序开发的社区容器映像

本文旨在介绍社区容器,用户可以从中提取和使用它们。 讨论了可供社区用户使用的三组容器。 这些是: Fedora、CentOS 和 CentOS 流。

容器之间有什么区别?

Fedora 容器基于最新的稳定 Fedora 内容和 CentOS-7 容器是基于 CentOS-7 的组件和相关的 SCLo SIG 组件。 最后,CentOS Stream 容器基于 CentOS Stream 8 或 CentOS Stream 9。

每个容器,例如 s2i-php-容器 或者 s2i-perl-容器, 包含可用于给定操作系统的相同包。 这意味着,从功能的角度来看,这些 example 容器分别提供 PHP 解释器或 Perl 解释器。

差异只能存在于每个发行版中可用的版本中。 为了 example:

Fedora PHP 容器在这些版本中可用:

CentOS-7 PHP 容器有以下版本:

CentOS Stream 9 PHP 容器有以下版本:

CentOS Stream 8 在这里没有提到 PHP 用例,因为用户可以直接从 Red Hat Container Catalog 注册表中提取它作为 全民基本收入 图片。 不基于 UBI 的容器在 CentOS Stream 8 存储库的 码头.io/sclorg 带有存储库后缀“-c8s”的命名空间。

Fedora 容器图像最近移动

这 Fedora 容器映像最近已移至 码头.io/fedora 注册机构。 他们都使用 Fedora:35, 然后 Fedora:36 ,作为基础镜像。 CentOS-7 容器存储在 码头。io/centos7 注册机构。 他们都使用 中央操作系统-7 作为基础镜像。

CentOS Stream 容器镜像

CentOS Stream 容器存储在 码头.io/sclorg 注册机构。

我们的 CentOS Stream 8 容器使用的基础镜像是 CentOS 流 8 带有标签“stream8”。

我们的 CentOS Stream 9 容器使用的基础镜像是 CentOS 流 9 带有标签“stream9”。

在这个注册机构中,每个容器都包含一个“后缀”,分别是 CentOS Stream 8 的“c8s”或 CentOS Stream 9 的“c9s”。

见容器 PHP-74 对于 CentOS Stream 9。

容器镜像更新和测试的频率

基于社区的容器以两种方式更新。

首先,当 github.com/sclorg 组织下的容器源中的拉取请求被合并时,GitHub 存储库中的相应版本被构建并推送到适当的存储库中。

其次,我们每个 GitHub 存储库中设置的 GitHub Actions 也实现了更新过程。 基础镜像,如“s2i-core”和“s2i-base”,在每周二下午 1:00 构建。 其余的集装箱在每周三下午 1:00 建造。

这意味着容器映像中的每个包更新或更改都会在几天内更新,不迟于一周后。

每个未超出其生命周期的容器都经过我们每晚构建的测试。 如果我们在某些容器上发现或检测到错误,我们会尝试修复它,但不提供任何保证。

我应该使用什么容器?

最后,我们提供了哪些容器? 这是一个很好的问题。 所有容器都存在于 GitHub 组织中 https://github.com/sclorg

这里总结了容器列表及其上游:

如何使用我选择的容器镜像?

所有容器映像都经过调整以在 OpenShift(或 好的 甚至 Kubernetes 本身)没有任何问题。 一些容器支持 source-to-image 构建策略,而一些容器预计将用作守护进程(例如数据库)。 有关具体步骤,请通过上述链接之一导航到相应容器映像的 GitHub 页面。

最后,一些真实的例子

让我们展示如何在我们支持的所有平台上使用 PHP 容器镜像。

首先,使用以下命令克隆容器 GitHub 存储库:

$ git clone https://github.com/sclorg/s2i-php-container

切换到克隆步骤创建的以下目录:

$ cd s2i-php-container/examples/from-dockerfile

Fedora example

首先拉动 Fedora 使用此命令的 PHP-80 图像:

$ podman pull quay.io/fedora/php-80

修改“Dockerfile”,使其引用 Fedora php-80 图像。 “Dockerfile”看起来像:

FROM quay.io/fedora/php-80

USER 0
# Add application sources
ADD app-src .
RUN chown -R 1001:0 .
USER 1001

# Install the dependencies
RUN TEMPFILE=$(mktemp) && 
    curl -o "$TEMPFILE" "https://getcomposer.org/installer" && 
    php <"$TEMPFILE" && 
    ./composer.phar install --no-interaction --no-ansi --optimize-autoloader

# Run script uses standard ways to configure the PHP application
# and execs httpd -D FOREGROUND at the end
# See more in <version>/s2i/bin/run in this repository.
# Shortly what the run script does: The httpd daemon and php need to be
# configured, so this script prepares the configuration based on the container
# parameters (e.g. available memory) and puts the configuration files into
# the appropriate places.
# This can obviously be done differently, and in that case, the final CMD
# should be set to "CMD httpd -D FOREGROUND" instead.
CMD /usr/libexec/s2i/run

检查应用程序是否正常工作

使用以下命令构建它:

$ podman build -f Dockerfile -t cakephp-app-80

现在使用以下命令运行应用程序:

$ podman run -ti --rm -p 8080:8080 cakephp-app-80

要检查 PHP 版本,请使用以下命令:

$ podman run -it –rm cakephp-app-80 bash
$ php –version

要检查一切是否正常,请使用以下命令:

$ curl -s -w ‘%{http_code}’ localhost:8080

这应该返回 HTTP 代码 200。如果您想查看网页,请在浏览器中输入“localhost:8080”。

CentOS 7 example

首先使用以下命令拉取 CentOS-7 PHP-73 映像:

$ podman pull quay.io/centos7/php-73-centos7

修改“Dockerfile”,使其引用 CentOS php-73 镜像。

“Dockerfile”看起来像这样:

FROM quay.io/centos7/php-73-centos7

USER 0
# Add application sources
ADD app-src .
RUN chown -R 1001:0 .
USER 1001

# Install the dependencies
RUN TEMPFILE=$(mktemp) && 
    curl -o "$TEMPFILE" "https://getcomposer.org/installer" && 
    php <"$TEMPFILE" && 
    ./composer.phar install --no-interaction --no-ansi --optimize-autoloader

# Run script uses standard ways to configure the PHP application
# and execs httpd -D FOREGROUND at the end
# See more in <version>/s2i/bin/run in this repository.
# Shortly what the run script does: The httpd daemon and php needs to be
# configured, so this script prepares the configuration based on the container
# parameters (e.g. available memory) and puts the configuration files into
# the appropriate places.
# This can obviously be done differently, and in that case, the final CMD
# should be set to "CMD httpd -D FOREGROUND" instead.
CMD /usr/libexec/s2i/run

检查应用程序是否正常工作

使用以下命令构建它:

$ podman build -f Dockerfile -t cakephp-app-73

现在使用以下命令运行应用程序:

$ podman run -ti --rm -p 8080:8080 cakephp-app-73

要检查 PHP 版本,请使用以下命令:

$ podman run -it –rm cakephp-app-73 bash
$ php –version

要检查一切是否正常,请使用以下命令:

curl -s -w ‘%{http_code}’ localhost:8080

它应该返回 HTTP 代码 200。如果您想查看网页,请在浏览器中输入 localhost:8080。

RHEL 9 UBI 9 真实 example

首先使用以下命令拉取基于 RHEL9 UBI 的 PHP-80 映像:

$ podman pull registry.access.redhat.com/ubi9/php-80

修改“Dockerfile”,使其引用 RHEL9 ubi9 php-80 映像。

“Dockerfile”看起来像:

FROM registry.access.redhat.com/ubi9/php-80

USER 0
# Add application sources
ADD app-src .
RUN chown -R 1001:0 .
USER 1001

# Install the dependencies
RUN TEMPFILE=$(mktemp) && 
    curl -o "$TEMPFILE" "https://getcomposer.org/installer" && 
    php <"$TEMPFILE" && 
    ./composer.phar install --no-interaction --no-ansi --optimize-autoloader

# Run script uses standard ways to configure the PHP application
# and execs httpd -D FOREGROUND at the end
# See more in <version>/s2i/bin/run in this repository.
# Shortly what the run script does: The httpd daemon and php needs to be
# configured, so this script prepares the configuration based on the container
# parameters (e.g. available memory) and puts the configuration files into
# the appropriate places.
# This can obviously be done differently, and in that case, the final CMD
# should be set to "CMD httpd -D FOREGROUND" instead.
CMD /usr/libexec/s2i/run

检查应用程序是否正常工作

使用以下命令构建它:

$ podman build -f Dockerfile -t cakephp-app-80-ubi9

现在使用以下命令运行应用程序:

$ podman run -ti --rm -p 8080:8080 cakephp-app-80-ubi9

要检查 PHP 版本,请使用以下命令:

$ podman run -it –rm cakephp-app-80-ubi9 bash
$ php –version

要检查一切是否正常,请使用以下命令:

curl -s -w ‘%{http_code}’ localhost:8080

它应该返回 HTTP 代码 200。如果您想查看网页,请在浏览器中输入 localhost:8080。

出现错误或增强时该怎么办

只需将错误(在 GitHub 中称为“问题”)甚至是带有修复的拉取请求,提交到上一节中提到的 GitHub 存储库之一。