在 rhel7 上创建自定义 NodeJSDocker 镜像

Creating a custom NodeJSDocker image on rhel7

我正在为我的组织构建一些基础 Docker 映像,供应用程序团队在 OpenShift 中部署应用程序时使用。我必须制作的图像之一是 NodeJS 图像(我们希望我们的图像是内部图像而不是来自 DockerHub)。我正在构建 RedHat 的 RHEL7 通用基础映像 (ubi)。但是我在配置 NodeJS 以在容器中工作时遇到问题。这是我的 Docker 文件:

FROM myimage_rhel7_base:1.0

USER root

RUN INSTALL_PKGS="rh-nodejs10 rh-nodejs10-npm rh-nodejs10-nodejs-nodemon nss_wrapper" && \
    yum install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \
    rpm -V $INSTALL_PKGS && \
    yum clean all

USER myuser

然而,当我 运行 图像时,没有 nodenpm 命令可用,除非我 运行 scl enable rh-nodejs10 bash。这在 Docker 文件中不起作用,因为它创建了一个子外壳,该子外壳将无法供访问容器的用户使用。

我已经尝试从源代码安装,但我有 运行 需要升级 gcc/g++ 版本的不同问题,尽管它们在我的组织配置的回购中不可用。我还认为,如果我可以让 NodeJS 从包管理器中工作,它将有助于获得安全补丁,并且应该更新包。

我的问题是,创建可用于在 NodeJS 上构建应用程序 运行ning 的图像的推荐步骤是什么?

可能在这种情况下,最好的代码是您根本不编写的代码。看看https://github.com/sclorg/s2i-nodejs-container

这是一个创建镜像的项目,安装了nodejs。这可能是一个开箱即用的完美解决方案,或者它也可以作为您尝试构建的一个很好的例子。

此外,他们的自述文件试图描述他们如何绕过 scl enable 命令。

Normally, SCL requires manual operation to enable the collection you want to use. This is burdensome and can be prone to error. The OpenShift S2I approach is to set Bash environment variables that serve to automatically enable the desired collection:

  • BASH_ENV: enables the collection for all non-interactive Bash sessions
  • ENV: enables the collection for all invocations of /bin/sh
  • PROMPT_COMMAND: enables the collection in interactive shell

Two examples: * If you specify BASH_ENV, then all your #!/bin/bash scripts do not need to call scl enable. * If you specify PROMPT_COMMAND, then on execution of the podman exec ... /bin/bash command, the collection will be automatically enabled.

我最终决定使用二进制文件而不是我们的 rpm 服务器来安装节点。这是实现

FROM myimage_rhel7_base:1.0

USER root

# Get node distribution from nexus and install it
RUN   wget -P /tmp http://myrepo.example.com/repository/node/node-v10.16.3-linux-x64.tar.xz && \
      tar -C /usr/local --strip-components 1 -xf /tmp/node-v10.16.3-linux-x64.tar.xz && \
      rm /tmp/node-v10.16.3-linux-x64.tar.xz