ItsMyLife
ItsMyLife

Reputation: 478

Npm install errror during docker container building

I created very simple docker file for my nodejs web application:

FROM node:8.11.4
FROM mysql:latest

WORKDIR /ess-explorer
COPY . .

RUN npm install

RUN cd config && cp config.json.example config.json && cp database.json.example database.json && cd ../

RUN npm run migrate

EXPOSE 3000
CMD ["npm", "dev"]

And docker.yml

version: '3'
services:

  essblockexplorer:
    container_name: ess-explorer
    build: .
    depends_on:
      - db
    privileged: true
    ports:
       - 3000:3000
       - 3010:3010

  db:
    container_name: mysql
    image: mysql
    restart: always
    volumes:
       - db-data:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: '123'

volumes:
  db-data:

After command docker-compose -f docker.yml build evey time I've got an error Step 5/9 : RUN npm install ---> Running in d3644d792807 /bin/sh: 1: npm: not found ERROR: Service 'essblockexplorer' failed to build: The command '/bin/sh -c npm install' returned a non-zero code: 127 What am i doing wrong? I found similar issues but i didnt find the real solution for solving this problem

Upvotes: 0

Views: 382

Answers (1)

Derek Brown
Derek Brown

Reputation: 4419

You shouldn't need the mysql image in your Dockerfile at all; ideally your app container (essblockexplorer) accesses the db container (db) via a NodeJS client. All you need to do is;

  1. Remove the FROM mysql:latest line from your Dockerfile.
  2. Access the MySQL database via a NodeJS client using (db) as the hostname (this is automatically loaded as an alias into your container).

Upvotes: 2

Related Questions