docker-compose up didn't finish npm install.

I’m new to docker-compose and I’d like to use it for my current development.

after I ran docker-compose up -d everything was starting ok and it looks good. But my nodejs application wasn’t installed correctly. It seems like npm install wasn’t complete and I had to do docker exec -it api bash to run npm i manually inside the container.

  • Adding bind-mounts to the containers for running a task in concourse
  • How to share java-packages between docker-container via link?
  • Which is the best way to pass AWS credentials to Docker container?
  • Nginx setup and v1/** endpoints access
  • Docker: Access mysql in docker container using --net=host option from host
  • .bash_profile does not work with docker php image
  • Here’s my docker-compose.

    version: '2'
    
    services:
      app:
        build: .
        container_name: sparrow-api-1
        volumes:
          - .:/usr/src/app
          - $HOME/.aws:/root/.aws
        working_dir: /usr/src/app
        environment:
          - SPARROW_EVENT_QUEUE_URL=amqp://guest:guest@rabbitmq:5672
          - REDIS_URL=redis
          - NSOLID_APPNAME=sparrow-api
          - NSOLID_HUB=registry:4001
          - NODE_ENV=local
          - REDIS_PORT=6379
          - NODE_PORT=8081
          - SOCKET_PORT=8002
          - ELASTICSEARCH_URL=elasticsearch
          - STDIN_OPEN=${STDIN_OPEN}
        networks:
         - default
        depends_on:
          - redis
          - rabbitmq
          - elasticsearch
        expose:
          - "8081"
        ports:
          - "8081:8081"
        command: bash docker-command.sh
    
    
      redis:
        container_name: redis
        image: redis:3.0.7-alpine
        networks:
         - default
        ports:
          - "6379:6379"
    
      rabbitmq:
        container_name: rabbitmq
        image: rabbitmq:3.6.2-management
        networks:
         - default
        ports:
          - "15672:15672"
    
      elasticsearch:
        container_name: elasticsearch
        image: elasticsearch:1.5.2
        networks:
         - default
        ports:
          - "9200:9200"
          - "9300:9300"
    
      registry:
        image: nodesource/nsolid-registry
        container_name: registry
        networks:
         - default
        ports:
          - 4001:4001
    
      proxy:
        image: nodesource/nsolid-hub
        container_name: hub
        networks:
         - default
        environment:
          - REGISTRY=registry:4001
          - NODE_DEBUG=nsolid
    
      console:
        image: nodesource/nsolid-console
        container_name: console
        networks:
         - default
        environment:
          - NODE_DEBUG=nsolid
          - NSOLID_APPNAME=console
          - NSOLID_HUB=registry:4001
        command: --hub hub:9000
        ports:
          - 3000:3000
    
    # don't forget to create network as well
    networks:
      default:
        driver: bridge
    

    Here’s my docker-command.sh

    #!/usr/bin/env bash
    
    # link the node modules to the root directory of our app, if not exists
    modules_link="/usr/src/app/node_modules"
    if [ ! -d "${modules_link}" ]; then
      ln -s /usr/lib/app/node_modules ${modules_link}
    fi
    
    if [ -n "$STDIN_OPEN" ]; then
      # if we want to be interactive with our app container, it needs to run in
      # the background
      tail -f /dev/null
    else
      nodemon
    fi
    

    Here’s my Dockerfile

    FROM nodesource/nsolid:latest
    
    RUN mkdir /usr/lib/app
    
    WORKDIR /usr/lib/app
    
    COPY [".npmrc", "package.json", "/usr/lib/app/"]
    
    RUN npm install \
      && npm install -g mocha \
      && npm install -g nodemon \
      && rm -rf package.json .npmrc
    

  • Freeswitch with docker
  • Docker /var/lib/docker/devicemapper/devicemapper using 2.7GB
  • docker-compose does not load up data
  • How to link multiple Docker containers and encapsulate the result?
  • npm install errors out saying ' Error: getaddrinfo ENOTFOUND npm.lab.myorg.com'
  • How to retrieve GOPATH from Docker container?
  • One Solution collect form web for “docker-compose up didn't finish npm install.”

    In your Dockerfile you are running npm install without any arguments first:

    RUN npm install \
      && npm install -g mocha \
    

    This will cause a non-zero exit code and due to the && the following commands are not executed. This should also fail the build though, so I’m guessing you already had a working image and added the npm instructions later. To rebuild the image use docker-compose build or simply docker-compose up --build. Per default docker-compose up will only build the image if it did not exist yet.

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