def format_container_output(output: bytes) -> str:
    """
    Format the output of a Docker container for printing or logging.

    Args:
      output: Raw bytes output by the container.

    Returns:
      Output formatted as a string.
    """
    # Decode bytestring, remove trailing newlines that get inserted.
    return output.decode("utf-8").rstrip("\n")