node-babel works very slow in Docker

Viewed 2963

I've setup a Docker container for developing of a node.js project. I want to use all ES6 features, so I use babel-node as the transpiler, but ran into a problem, that trasnpiling process takes too much time in Docker.

I am mounting app directory from my host (so I can make edits in webstorm), and I use nodemon to track all the changes and restart automatically the server.

 docker build -t lazarev/an_app .
 docker run -d -p 49160:8080 --name map -v $HOME/projects/app:/usr/src/app lazarev/an_app tail -f /dev/null

nodemon -l commang is set in a shell script, that is set in ENTRYPOINT in my Dockerfile.

Dockerfile:

FROM node:argon
MAINTAINER Lazarev Alexandr <lazarev@elje-group.com>

RUN mkdir /docker-entrypoint
ADD ./bootstrap.sh /docker-entrypoint

RUN locale -a

EXPOSE 8080

RUN npm install nodemon -g
RUN npm install babel-cli -g

ENTRYPOINT ["/docker-entrypoint/bootstrap.sh"]

bootstarp.sh:

 #!/bin/bash
echo "******INSTALL NODE MODULES******"

npm install
date
echo "******RUN THE SERVER******"
nodemon -L
date

packege.json:

{
  "name": "app",
  "version": "1.0.0",
  "description": "desc",
  "author": "Lazarev Alexandr <lazarev@elje-group.com>",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "babel-node --presets es2015 --debug server.js"
  },
  "license": "ISC",
  "dependencies": {
    "express": "^4.13.4",
    "mapnik": "^3.5.2",
    "babel-preset-es2015": "^6.6.0"
  }
}

It might look strange why I use bootstrap.sh but there are other commands that I didn't paste here.

So, my problem is that after I do some changes on my host, nodemon detects changes immediately, but server restart takes about half of a minute. Without compiling ES6 via babel it is considerably faster.

Also, when I run same project on my host (my host machine is a MacbookPro with 2.5 GHz Intel Core i7 processor and 16gb ram), omitting Docker, everything is fast enough. So I'm convinced that the problem is in the Docker.

My question is: Why babel-node is transpiling so slow in the Docker Container? It there s way to throttle it?

1 Answers
Related