No colors in docker run output

Hello,

Can you tell why I have no colors in docker run -ti --rm --name backupctl backupctl -h output and how can I fix it?

Python code responsible for building argparse-based CLI interface:

def register_repo_cmd(subparsers: SubParsers) -> None:
    repo_parser = subparsers.add_parser('repo', help='manage backup repositories')
    repo_subparsers = repo_parser.add_subparsers(dest='command', required=True)
    repo_subparsers.add_parser('init', help='initialize repository')
    repo_subparsers.add_parser('check', help='check repository for inconsistencies')


def register_backup_cmd(subparsers: SubParsers) -> None:
    backup_parser = subparsers.add_parser('backup', help='create backup')
    backup_subparsers = backup_parser.add_subparsers(dest='resource', required=True)
    backup_subparsers.add_parser('databases', help='backup databases')
    backup_subparsers.add_parser('filesystem', help='backup filesystem')


def register_restore_cmd(subparsers: SubParsers) -> None:
    restore_parser = subparsers.add_parser('restore', help='restore backup')
    restore_subparsers = restore_parser.add_subparsers(dest='resource', required=True)
    restore_subparsers.add_parser('databases', help='restore databases')
    restore_subparsers.add_parser('filesystem', help='restore filesystem')


def build_parser() -> ArgumentParser:
    parser = ArgumentParser()
    parser.add_argument('-c', '--config', dest='config', help='path to config file')
    subparsers = parser.add_subparsers(dest='command')
    register_repo_cmd(subparsers)
    register_backup_cmd(subparsers)
    register_restore_cmd(subparsers)
    return parser

Similarly, powerlevel10k prompt doesn’t have proper colorrs when I try to login into zsh on my Docker image whiteman808/devshell using docker run -ti --rm whiteman808/devshell:debian-trixie zsh which has embedded dotfiles and zsh+p10k. I’ll be thankful for any answers how to fix it too.

Depends on the app that produces the colored output. If you run

docker run --rm -ti bash -la

You should get a colored list of folders. but not when you only run

docker run --rm bash -la

because the interactive terminal was the requirement for bash. If the app decides whether it should use colors or not based on something else, it will not send the control characters that make the colors. The documentation of the app should describe what it requires for generating colored outputs.

2 Likes