def get_containerfile(
    bento_tag: Tag | str,
    output_path: str | None = None,
    enable_buildkit: bool = True,
    features: t.Sequence[str] | None = None,
    _bento_store: BentoStore = Provide[BentoMLContainer.bento_store],
):
    """
    Returns the generated container file for a given Bento.

    Note that the container file (Dockerfile) inside the Bento is minimal, whereas
    this utility functions returns the container file that :ref:`bentoml containerize <reference/cli:containerize>` will
    be using.

    .. note::

        If ``output_path`` is not specified, then the contents of the container file
        will be printed out to ``sys.stderr``. If provided, then the final container file
        will be written to that given path.

    Args:
        bento_tag: Given tag for the bento.
        output_path: Optional output path to write the final container file to.
                     Note that if ``output_path`` is a directory, then the targeted file
                     will be ``output_path + os.sep + "<bento_tag>.dockerfile"``.
        enable_buildkit: Whether the container file contains BuildKit syntax.
        features: Optional features to include in the container file. See :ref:`concepts/bento:Python packages`
                  for additional BentoML features.
    """
    bento = _bento_store.get(bento_tag)
    with _internal_construct_containerfile(
        bento,
        enable_buildkit=enable_buildkit,
        features=features,
        add_header=True,
    ) as (_, final_containerfile):
        if output_path is not None:
            if os.path.isdir(output_path):
                output_path = output_path = os.path.join(
                    output_path, f"{bento.tag.path().replace(os.sep, '_')}.dockerfile"
                )
            logger.info(
                "Writting Containerfile for '%s' to '%s'.", bento.tag, output_path
            )
            shutil.copyfile(final_containerfile, output_path)
            return
        # otherwise we will just write this to stderr.
        with open(final_containerfile, "r") as f:
            sys.stderr.write(f.read())
Returns the generated container file for a given Bento.

Note that the container file (Dockerfile) inside the Bento is minimal, whereas
this utility functions returns the container file that :ref:`bentoml containerize <reference/cli:containerize>` will
be using.

.. note::

If ``output_path`` is not specified, then the contents of the container file
will be printed out to ``sys.stderr``. If provided, then the final container file
will be written to that given path.

Args:
bento_tag: Given tag for the bento.
output_path: Optional output path to write the final container file to.
Note that if ``output_path`` is a directory, then the targeted file
will be ``output_path + os.sep + "<bento_tag>.dockerfile"``.
enable_buildkit: Whether the container file contains BuildKit syntax.
features: Optional features to include in the container file. See :ref:`concepts/bento:Python packages`
for additional BentoML features.
src/bentoml/container.py