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:

  • Use separate docker container for code only
  • How to find out all the images which are created by performing commit on the particular container?
  • Random GET /nginx_status call from inside docker container
  • Can't connect to Neo
  • How to run a new Jupyter Notebook file that's not part of a pre-built docker image in docker?
  • Docker Container Library Duplication
  • 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 dynamically change the docker's base image
  • Mount data volume, then create symbolic link at container creation in docker
  • How to remove docker images based on name?
  • Multiple docker images run from docker file
  • delete image from docker registry v2
  • Run LiveServerTestCase from Docker Selenium with Django 1.11
  • 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.