D
D
Dmitry Tarasov2020-02-04 19:01:07
Node.js
Dmitry Tarasov, 2020-02-04 19:01:07

How to raise node.js + mysql via docker-compose?

What is the problem ?
When running docker-compose up --build gives
this error, I understand that the problem is in the COPY command, but I do not understand what exactly is wrong.

Building app
Step 1/6 : FROM node:11
 ---> 5b97b72da029
Step 2/6 : WORKDIR /src
 ---> Using cache
 ---> a33787f5ff60
Step 3/6 : COPY package*.json /src
ERROR: Service 'app' failed to build: COPY failed: no source files were specified


5e3994845b8ae451137625.png

Docker/node/Dockerfile structure
FROM node:11
WORKDIR /src
COPY package*.json /src
RUN npm install mysql
COPY . .
CMD ["node", "index.js"]


docker-compose.yml file

version: '3.7'
services: 
    db: 
        image: mysql:5.7
        ports: 
            - 3306:3306
        expose: 
            - 3306
        environment:
            MYSQL_ROOT_PASSWORD: '${MYSQL_ROOT_PASSWORD}'
            MYSQL_DATABASE: '${MYSQL_DATABASE}'
            MYSQL_USER: '${MYSQL_USER}'
            MYSQL_PASSWORD: '${MYSQL_PASSWORD}'
    app: 
        build: ./docker/node/
        image: nodejs
        container_name: nodejs
        restart: unless-stopped
        environment: 
            MYSQL_HOST: '${MYSQL_HOST}'
            MYSQL_DATABASE: '${MYSQL_DATABASE}'
            MYSQL_USER: '${MYSQL_USER}'
            MYSQL_PASSWORD: '${MYSQL_PASSWORD}'
            MYSQL_PORT: 3306
        volumes: 
            - ./src:/src/
        ports: 
            - 3000:3000
        depends_on:
            - db

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Georg Gaal, 2020-02-04
@fast-je

Build comes from the current directory. The file with the package in the Dockerfile is relative to the src directory
This is the error
Most likely - the easiest way to solve it is to add it to context: ./srcthe docker compose
And I highly recommend that you familiarize yourself with the concept of docker context

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question