Bash script fails to run node on docker image

I have an app that I want to run on a single self contained Docker image.
I had it running fine on an Ubuntu based image, but the same script now causes me trouble on Alpine.

Here is my docker file :

  • Error starting Windows docker container with managed service account
  • rsyslog inside docker containers => “rsyslogd is not running … failed”
  • docker-compose with a war via volume fails on digital ocean debian but not other debian distros (my home box, work box as well)
  • CentOS disable service (docker) before boot?
  • Can't register code-push
  • Volume not really mounted to docker container on IBM Bluemix
  • FROM julienlengrand/alpine-node-rethinkdb
    # Preparing
    # RUN ln -snf /bin/bash /bin/sh
    # # Define mountable directories.
    VOLUME ["/data"]
    # # Define working directory.
    WORKDIR /data
    # # Install app dependencies
    COPY package.json /data
    RUN npm install
    # # Bundle app source
    COPY . /data
    # # Expose rethinkdb ports.
    #   - 8080: web UI
    #   - 28015: process
    #   - 29015: cluster
    EXPOSE 8080
    #EXPOSE 28015
    #EXPOSE 29015
    # Expose node app ports
    EXPOSE 4567
    CMD [ "/bin/sh", "/data/" ]

    My startApp script is relatively simple :

    rethinkdb --bind all & sleep 1; node dbCreate.js; sleep 2; nohup node workers/worker.js & node app.js

    But when I try to run it, I get the following error:

        throw err;
    'rror: Cannot find module '/data/app.js
        at Function.Module._resolveFilename (module.js:440:15)
        at Function.Module._load (module.js:388:25)
        at Module.runMain (module.js:575:10)
        at run (bootstrap_node.js:352:7)
        at startup (bootstrap_node.js:144:9)
        at bootstrap_node.js:467:3

    This happens whether I run it automatically, or directly within the image using the shell.

    I have checked and everything is correctly placed in the data folder.
    Additionally, if I run all the commands one after the other directly in the sh shell everything runs as expected.

    I have also tried to simplify my script as such :

    rethinkdb --bind all & sleep 1; node dbCreate.js; sleep 2; node app.js

    bu the same issue happens.

    Any idea what can go wrong? What could make my /data folder unavailable when running via the startApp script? Could it be that it is a specificity from Alpine?


  • What does --net=host option in Docker command really do?
  • How to scale application with multiple exposed ports and multiple volume mounted by using docker swarm?
  • is there a way to negate a pattern in .dockerignore?
  • Deploy a Jekyll site from Gitlab with Gitlab CD?
  • Install and initialize kerberos KDC on docker VM
  • Deploying ASP.NET 5 app to EC2 in a Docker container
  • One Solution collect form web for “Bash script fails to run node on docker image”

    The error message you are receiving looks like a classic carriage return issue as the quote after app.js has moved to the start of the line

    'rror: Cannot find module '/data/app.js

    Node should normally be able to deal with both line endings but shell scripts aren’t so kind.

    I generally default all projects/files/editors/git to a Unix \n unless there are specific requirements not too.

    You can convert existing files with dos2unix or one of the answers in the question jlengrand found. I like perl -pi -e 's/\r\n/\n/g', because pie

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.