Docker compose not finding my index.js

I’m following this guide and use my low docker knowledge to get a dev environment up and running. I’ve hit a wall I cannot solve. This is my docker-compose.yml:

version: '2'
services:
  redis:
    image: redis:3.2
  mongo:
    image: mongo:3.2
  app:
    build: .
    ports:
      - '3000:3000'
    command: './node_modules/.bin/nodemon ./index.js'
    environment:
      NODE_ENV: development
    volumes:
      - .:/home/app/cardcreator
      - /home/app/cardcreator/node_modules
    depends_on:
      - redis
      - mongo
    links:
      - redis
      - mongo

and this is my Dockerfile:

  • Sending build context to Docker daemon (it doesn't stop)
  • Getting started with Laradock on Mac
  • docker-compose with a war via volume fails on digital ocean debian but not other debian distros (my home box, work box as well)
  • How do I connect a Docker container running in boot2docker to a network service running on another host?
  • When and when not to use tty in Docker Remote API
  • How to use Let's Encrypt with Docker container based on the Node.js image
  • FROM node:6.3.1
    
    RUN useradd --user-group --create-home --shell /bin/false app
    
    ENV HOME=/home/app
    
    COPY package.json npm-shrinkwrap.json $HOME/cardcreator/
    RUN chown -R app:app $HOME/*
    
    USER app
    WORKDIR $HOME/cardcreator
    RUN npm install
    
    USER root
    COPY . $HOME/cardcreator/
    RUN chown -R app:app $HOME/*
    USER app
    
    CMD ["node", "index.js"]
    

    When I try to start the app via docker-compose up, I get the error

    app_1    |   Usage: nodemon [nodemon options] [script.js] [args]
    app_1    |   See "nodemon --help" for more.
    

    I then removed the command line of my docker-compose.yml, only leaving node index.js to start. I get an error saying index.js cannot be found.

    The file is in my project folder, it is there and it has content. I can’t figure out why this setup doesn’t work, I did similar setups for tails and it worked fine.

    Can anyone tell me what I’m doing wrong here?

  • How to configure a Jenkinsfile to build docker image and push it to a private registry
  • Set symfony cache directory in parameters
  • sensitive information required for docker build
  • How can I Provide Permissions to a PHP Docker Image and Host VOLUME?
  • Docker + Cassandra ulimit error
  • unable to import large database to docker mysql container
  • 2 Solutions collect form web for “Docker compose not finding my index.js”

    Whatever you are mounting in your compose file here:

    - .:/home/app/cardcreator
    

    Is going to mount on top of whatever you built in $HOME/cardcreator/ in your Dockerfile.

    So basically you seem to have conflicting volumes — it’s an order of operations issue — the build is going to happen first and the volume mount happens later when the container runs, so your container will no longer have access to the files built in the Dockerfile.

    You could try to use

    docker exec -it app_1 bash
    

    to go into the container, trying to execute the

    node index.js 
    

    command manually and see what’s going on. Not 100% sure if the ‘node’ docker images have bash installed though..

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