0
respostas

Erro no quando executo o docker-compose build

Quando executo o docker-compose build da erro. Não entendi o motivo do erro

alura-books.dockerfile

FROM node:latest
LABEL autor="Rafael Miranda"
ENV NODE_ENV=development
COPY . /var/www
WORKDIR /var/www
RUN npm install -g npm@7.16.0
RUN npm install 
ENTRYPOINT ["npm", "start"]
EXPOSE 3000

docker-compose.yml

version: '3'
services:
    nginx:
        build:
            dockerfile: ./nginx.dockerfile
            context: .
        image: rafaelmiranda/nginx
        container_name: nginx
        ports:
          - "80:80"
        networks: 
          - production-network
        depends_on: 
          - "node1"
          - "node2"
          - "node3"
    mongodb:
        image: mongo
        networks: 
          - production-network
    node1:
        build: 
            dockerfile: ./alura-books.dockerfile
            context: .
        image: rafaelmiranda/alura-books
        container_name: alura-books-1
        ports:
            - "3000"
        networks:
            - production-network
        depends_on:
            - "mongodb"
    node2:
        build: 
            dockerfile: ./alura-books.dockerfile
            context: .
        image: rafaelmiranda/alura-books
        container_name: alura-books-2
        ports:
            - "3000"
        networks:
            - production-network
        depends_on:
            - "mongodb"
    node3:
        build: 
            dockerfile: ./alura-books.dockerfile
            context: .
        image: rafaelmiranda/alura-books
        container_name: alura-books-3
        ports:
            - "3000"
        networks:
            - production-network
        depends_on:
            - "mongodb"
networks: 
  production-network:
    driver: brige


Output quando executo o docker-compose build

mongodb uses an image, skipping
Building node1
[+] Building 19.9s (9/9) FINISHED
 => [internal] load build definition from alura-books.dockerfile                                        0.1s 
 => => transferring dockerfile: 241B                                                                    0.0s 
 => [internal] load .dockerignore                                                                       0.0s 
 => => transferring context: 2B                                                                         0.0s 
 => [internal] load metadata for docker.io/library/node:latest                                          0.0s 
 => [internal] load build context                                                                       0.0s 
 => => transferring context: 378B                                                                       0.0s 
 => CACHED [1/5] FROM docker.io/library/node:latest                                                     0.0s 
 => [2/5] COPY . /var/www                                                                               0.1s 
 => [3/5] WORKDIR /var/www                                                                              0.1s 
 => [4/5] RUN npm install -g npm@7.16.0                                                                18.3s 
 => ERROR [5/5] RUN npm install                                                                         1.2s 
------
 > [5/5] RUN npm install:
#9 1.109 npm ERR! code ENOENT
#9 1.112 npm ERR! syscall open
#9 1.113 npm ERR! path /var/www/package.json
#9 1.113 npm ERR! errno -2
#9 1.117 npm ERR! enoent ENOENT: no such file or directory, open '/var/www/package.json'
#9 1.117 npm ERR! enoent This is related to npm not being able to find a file.
#9 1.117 npm ERR! enoent
#9 1.131
#9 1.132 npm ERR! A complete log of this run can be found in:
#9 1.132 npm ERR!     /root/.npm/_logs/2021-06-07T00_27_34_389Z-debug.log
------
executor failed running [/bin/sh -c npm install]: exit code: 254
ERROR: Service 'node1' failed to build : Build failed