搜索

第 2 章 使用 Red Hat Software Collections 容器镜像构建应用镜像

download PDF

您可以使用 Red Hat Software Collections 容器镜像构建应用程序镜像的几个选项:

  • 使用红帽提供的容器镜像作为基础镜像
  • 使用 S2I 脚本的 Dockerfile
  • 在 OpenShift 中使用 Source-to-Image
  • 使用 source-to-image 实用程序

2.1. 使用 Red Hat Software Collections 镜像构建应用程序镜像作为基础镜像

使用红帽提供的容器镜像作为基础镜像:

  1. 为您的应用程序镜像创建一个 Dockerfile,并确保该文件包含以下行:

    FROM registry.redhat.io/rhscl_image_name
  2. 通过将以下行放在 Dockerfile 中,将应用程序代码添加到镜像中:

    ADD src /opt/app-root/src
  3. 使用 podman 构建应用程序镜像:

    # podman build -t application_image_name .
  4. 使用 podman 运行应用程序镜像。例如,要在应用程序镜像中启动交互式 shell,请运行:

    # podman run -ti application_image_name /bin/bash -l

例 2.1. 使用 rhscl/python-38-rhel7 基础镜像从 Dockerfile 构建的 Django 应用

本例演示了一个 Dockerfile,可用于从 rhscl/python-38-rhel7 容器镜像创建简单 Django 应用。

# Set base image
FROM registry.redhat.io/rhscl/python-38-rhel7

# Add application sources
ADD --chown=1001:0 app-src .

# Install the dependencies
RUN pip install -U "pip>=19.3.1" && \
    pip install -r requirements.txt && \
    python manage.py collectstatic --noinput && \
    python manage.py migrate

# Run the application
CMD python manage.py runserver 0.0.0.0:8080
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.