1

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:

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
  • What Docker version and environment are you running on? It looks like your volume mount isn't happening the way you expect, which is common with Docker VM's running inside Mac/Win. Commented Aug 6, 2016 at 14:01
  • @BMitch I do indeed run Docker 1.12 on Windows 10. Any suggestions? Commented Aug 6, 2016 at 14:04

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

You're right, that's it! But I used that config option before, for rails stuff - to avoid having to rebuild the entire app every time I change a file. Guess I can't do this here for some reason?
You just need to design your directory structure so the files you want to be able to change don't conflict with the files you build in your Dockerfile. If you structure your Dockerfile so the files you change are in the last run statements, it will re-use any layers created above, so the re-build should be pretty fast. You can even run tests in your build to check for introduced errors. Generally, there shouldn't be a reason to store node_modules on a volume. You can even link to a single file or two if you want but it's nice if the entire app can be immutable/self-contained.
0

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..

1 Comment

They do but since the Docker command stops with an error, the container is stopped right away and I can't get any commands to run on it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.