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'
    image: redis:3.2
    image: mongo:3.2
    build: .
      - '3000:3000'
    command: './node_modules/.bin/nodemon ./index.js'
      NODE_ENV: development
      - .:/home/app/cardcreator
      - /home/app/cardcreator/node_modules
      - redis
      - mongo
      - redis
      - mongo

and this is my Dockerfile:

  • create_network(): failed to allocate gateway (x.x.x.x): Address already in use in test case
  • Jenkins build inside a docker container with generated reports
  • connect to mysql database from docker container
  • Connecting go and postgres with docker-compose
  • Setup & scale titan/cassandra on AWS EC2 using docker
  • Kubernetes multinode setup cannot remove docker0 interface
  • 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?

  • Nginx doesn't run with my dockers containers
  • Dockerfile : not able to use add to map local file to container
  • On Bluemix - handling volume for container group instances
  • FROM Command in Docker File
  • Sensu /checks API call appears empty
  • Should I use forever/pm2 within a (Docker) 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.