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
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
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?
2 Solutions collect form web for “Docker compose not finding my index.js”
Whatever you are mounting in your compose file here:
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
command manually and see what’s going on. Not 100% sure if the ‘node’ docker images have bash installed though..