3

This might be a little bit of a complex question but I am open to try any and all suggestions thrown at me.

I am running a docker instance which clones a git repository, it is a php 7 apache docker instance:

FROM php:7.0-apache

With the Symfony Process Component I am booting up my container and pass my environment variables.

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

I have added the xterm-256-color environment to make sure I am getting colored output(correct me if this is wrong).

To display the output of the container I am using the Symfony Process Component to send it to a websocket.

$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 a webpage in realtime.

The problem is that I want to display the docker output with proper coloring as you would normally see it with a terminal. All formatting and coloring seems to be lost at this point though.

Is there any web I can pass the docker output to a websocket and still maintain my coloring to display on a webpage?

Any hints or tips to guide me in the right direction are welcome since I am asking a lot here.

Thanks for readings, cheers.

Edit

To be clear I am not yet getting any colored output so far the output given to me from the docker container looks simply 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)
Stephan-v
  • 19,255
  • 31
  • 115
  • 201
  • 1
    What is the format of the colorized output? ANSI colors? (i.e. the terminal colors). If that is the case, you will need something to convert it to HTML colors, that is another story. Something like this: https://github.com/sensiolabs/ansi-to-html – Robert May 15 '17 at 21:25
  • I don't seem to be getting any formatting from what I can tell if I pass it on to a websocket. When I output it to a logfile I am also not getting colored output. When I actually dive into my container like so: `docker run -it -e REPOSITORY="https://github.com/stephan-v/test.git" arbiter` I am getting colorized output though. – Stephan-v May 15 '17 at 21:33

1 Answers1

2

In this case I simply had to add a -t flag to my docker run command. I was trying to add -it which led to an error. Obviously that my bad and not necessary since there is nothing interactive about this process.

After adding the -t flag like in the example below the ANSI symbols started showing up:

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

I am formatting the ANSI symbols with the provided library from @Robert everything works perfectly fine now. When executing:

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

I just had to remember to also pass the generated HTML's string length and it all renders perfect.

Stephan-v
  • 19,255
  • 31
  • 115
  • 201