第1章 Creating a modelcar image and pushing it to a container image registry


You can create a modelcar image that contains a language model that you can deploy with Red Hat AI Inference Server.

To create a modelcar image, download the model from Hugging Face and then package it into a container image and push the modelcar container to an image registry.

Prerequisites

  • You have installed Python 3.11 or later.
  • You have installed Podman or Docker.
  • You have access to the internet to download models from Hugging Face.
  • You have configured a container image registry that you can push images to and have logged in.

Procedure

  1. Create a Python virtual environment and install the huggingface_hub Python library:

    python3 -m venv venv && \
    source venv/bin/activate && \
    pip install --upgrade pip && \
    pip install huggingface_hub
  2. Create a model downloader Python script:

    vi download_model.py
  3. Add the following content to the download_model.py file, adjusting the value for model_repo as required:

    from huggingface_hub import snapshot_download
    
    # Specify the Hugging Face repository containing the model
    model_repo = "ibm-granite/granite-3.1-2b-instruct"
    snapshot_download(
        repo_id=model_repo,
        local_dir="/models",
        allow_patterns=["*.safetensors", "*.json", "*.txt"],
    )
  4. Create a Dockerfile for the modelcar:

    FROM registry.access.redhat.com/ubi9/python-311:latest as base
    
    USER root
    
    RUN pip install huggingface-hub
    
    # Download the model file from Hugging Face
    COPY download_model.py .
    
    RUN python download_model.py
    
    # Final image containing only the essential model files
    FROM registry.access.redhat.com/ubi9/ubi-micro:9.4
    
    # Copy the model files from the base container
    COPY --from=base /models /models
    
    USER 1001
  5. Build the modelcar image:

    podman build . -t modelcar-example:latest --platform linux/amd64

    Example output

    Successfully tagged localhost/modelcar-example:latest

  6. Push the modelcar image to the container registry. For example:

    $ podman push modelcar-example:latest quay.io/<your_model_registry>/modelcar-example:latest

    Example output

    Getting image source signatures
    Copying blob b2ed7134f853 done
    Copying config 4afd393610 done
    Writing manifest to image destination
    Storing signatures

Red Hat logoGithubRedditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

Red Hat ドキュメントについて

Legal Notice

Theme

© 2026 Red Hat
トップに戻る