Starting an app fails

I have a node.js app that compiles the runtime version into the dist folder. therefore the package.json file specifies the start script node dist/index.js.

I now want to containerize it but the container doesn’t need to have the distribution directory and those files really should live in the root of the app, thus my Dockerfile contains the lines

  • Bluemix: service bound to container does not appear in VCAP_SERVICES
  • {“message”:“No such image: jenkins_slave_1:latest”}
  • Runtime constraints on CPU and memory with docker containers
  • Dockerfile COPY files not showing on VOLUME
  • Synchronizing numeric user id's between Dockerfiles and docker-compose.yml?
  • GitlabCI free shared runners to provision Ubuntu instead of CoreOS?
  • COPY package.json /usr/src/app/
    COPY dist/* /usr/src/app/

    which places the runtime files in the image. the problem I have is that when the docker file issues its last command:

    CMD ["npm", "start"]

    it fails because the index.js is now in the wrong location (because it’s looking for it in the non-existent distribution directory). I could solve the problem by issuing:

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

    instead but that seems like the wrong thing to do. what is the correct approach?

    * update I *

    I had modified the index.js so it could run from the root of the project (i.e. it expects to find the resources it needs in the dist/ folder) by issuing a node dist/index.js, but of course, this is now also a problem since there is no distribution directory. how is this generally approached?

  • Docker swarm — container binding to ethx IP
  • Docker separation of processes and source code control
  • How to mount docker volume into my docker project using compose?
  • Setup local Wordpress development environment with Docker error 500
  • install/access executable for existing docker container
  • nginx alpine docker fails without previous ls?
  • One Solution collect form web for “Starting an app fails”

    I would code all your javascript require calls relative to the current file with no reference to the “dist” directory. So let’s say you have index.js and routes.js in the project root. index.js loads routes via var routes = require('./routes'). When you compile these, compile BOTH of them into the dist directory and all should be well.

    If you want to run via npm start from the project root, you can configure that to do node dist/index.js.

    For docker, there’s no reason to use npm at all to launch your app. It’s an unnecessary process executing for no benefit. Just launch via node index.js in your dockerfile with WORKDIR /usr/src/app.

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