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.

  • Why are large files in my Docker image getting pushed each time even when no changes have been made to them?
  • How to investigate the differences between two Docker images of Ubuntu?
  • PHP docker best way. Build application inside or outside docker? [closed]
  • Docker add additional arguments to start
  • Docker container - how to configure so it gets a viable IP address when running in vagrant?
  • git clone (SSH) gets reaped by supervisord run in docker
  • 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
    

  • Want to ssh into a running docker container running inside CentOs Image
  • Can't start docker-compose with systemd: “aufs au_opts_verify: dirperm1 breaks the protection by the permission bits on the lower branch” error
  • Docker on several computers
  • Running docker container through mitmproxy
  • How to stop docker
  • How to connect Docker from another host?
  • 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.