How to enable colors in a Docker container?

Viewed 5274

Context

I have a Docker Compose with which I run several containers. My docker-compose.yml:

version: '2'

services:
  web:
    build: ../application-web/
    ports:
     - "80:80"
    tty: true
    # Add a volume to link php code on the host and inside the container
    volumes:
     - ${application_PATH}:/usr/share/application
     - ${application_PATH}/docker_files/docker-assistant:/usr/share/assistant
    depends_on:
     - custom-php
     - custom-mysql
    links:
     - custom-php:custom-php
     - custom-mysql:custom-mysql

  custom-php:
    build: ../application-php/
    ports:
     - "50:50"
    tty: true
    volumes:
     - ${application_PATH}:/usr/share/application
     - ${application_PATH}/docker_files/docker-assistant:/usr/share/assistant

  custom-mysql:
    build: ../application-mysql/
    tty: true
    volumes:
     - ${MYSQL_DATA_PATH}:${MYSQL_DATA_PATH}
     - ${application_PATH}/sql:/usr/share/sql
     - /tmp/mysql:/var/data/mysql
    environment:
     - MYSQL_ALLOW_EMPTY_PASSWORD=yes
     - MYSQL_DATABASE=applicationdb
     - MYSQL_USER=root
     - TZ=Europe/Paris

We use the custom-php container to run unit tests in command line. Before using Docker, unit tests displayed colors in the terminal (green if everything is fine, red for each error, skipped tests in blue).

Problem

Now, return of unit tests are all in the same color. Plus when I connect myself to a running container using docker exec -it compose_custom-php_1 bash, it doesn't display color either.

I tried to add the environment variable TERM=xterm like this post suggest: Docker bash prompt not display color. I put it in my Dockerfile, and it works because some commands that was not working now can be executed (e.G. ctrl + L). But not the colors...

Question

What is my problem? What am I doing wrong and how can I enable colors in Docker containers?

0 Answers
Related