Colored output from docker to websocket

This may be a bit of a tricky question, but I'm open to trying everything and every suggestion thrown at me.

I start a docker instance that clones a git repository, this is a php 7 apache docker instance:

FROM php:7.0-apache

      

With Symfony Process Component I load my container and pass environment variables.

"docker run -e REPOSITORY=\"{$url}\" 
-e COMPOSER_ALLOW_SUPERUSER=1 
-e TERM='xterm-256color' arbiter bash -l"

      

I added an environment xterm-256-color

to make sure I get colored output (correct me if this is not the case).

To display the output of a container, I am using a Symfony component component to post it to a website.

$process->run(function ($type, $buffer) use ($socket) {
    socket_write($socket, $buffer, strlen($buffer));
});

      

At this point, I can use something like socket.io to display it on the webpage in real time.

The problem is, I want to display the docker output with the correct coloring as you would normally see it with a terminal. At this point all formatting and coloring are lost.

Is there any website that I can pipe the docker output to a websocket and still save my coloring for display on the webpage?

Any hints or advice to guide me in the right direction is appreciated as I ask a lot here.

Thanks for the testimony, greetings.

Edit

To be clear I am not getting any color output yet, the output I got from the docker container just looks like this (composer example):

[2017-02-12 01:02:56] local.INFO: remote: Counting objects: 69, done.        
remote: Compressing objects:   2% (1/47)           
remote: Compressing objects:   4% (2/47)

      

+3


source to share


1 answer


In this case, I just had to add the -t flag to my docker run command. I tried to add -it

which resulted in an error. Obviously I'm bad and unnecessary, as there is nothing interactive about the process.

After adding the flag -t

like in the example below, ANSI characters started showing:

docker run -t 
-e REPOSITORY=\"{$url}\" 
-e COMPOSER_ALLOW_SUPERUSER=1 
-e TERM='xterm' arbiter

      



I am formatting ANSI characters with the provided library from @Robert everything works fine now. By doing:

socket_write($socket, $buffer, strlen($buffer));

      

I just needed to remember to pass the generated HTML string length and it all makes perfect.

+2


source







All Articles