Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker logs not showing colors (express + nodejs image)

Tags:

node.js

docker

A petty, yet interesting question (for me):

I'm trying to create docker image from a small server( nodejs + express) I wrote. My server code is:

var express = require('express');
var Inflector = require('inflected');
var colors = require('colors');

var app = express();

app.get('/hello/:name', function(req, res, next){
    var name = Inflector.titleize(req.params.name);
    console.log("Saying hello to " + name.yellow);
    res.send('Hello ' + name);
});

var port = 9090;
app.listen(port, function(){
    console.log(('App is running on port ' + port).inverse);
});

I'm creating my image with this Dockerfile:

FROM centos:centos6

RUN     rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm

RUN     yum install -y npm

COPY . /src

RUN cd /src; npm install

EXPOSE 9090

CMD ["node", "/src/index.js"]

Building and running the image with the common commands:

docker build -t username:centos-nodejs
docker run -p 9090:9090 username:centos-nodejs

I was expecting the logs to show up with colors in the command line as they do without docker (e.g. node index.js).

What is the cause and can I fix this?

like image 999
Shikloshi Avatar asked Sep 18 '25 10:09

Shikloshi


1 Answers

You need to run your container with "-it" options:

docker run -it -p 9090:9090 username:centos-nodejs
like image 143
Alex da Silva Avatar answered Sep 20 '25 02:09

Alex da Silva