简体   繁体   中英

docker-compose.yml issue nodejs and mysql

I trying to dockerize my nodeJS api. Check out the following files :

.\\package.json

{
  "name": "test-api",
  "version": "1.0.0",
  "description": "TBD",
  "scripts": {
    "start": "node ./bin/www"
  },
  "keywords": [
    "test",
    "API"
  ],
  "author": "test",
  "dependencies": {
    "bcrypt": "^2.0.1",
    "bcrypt-promise": "^2.0.0",
    "body-parser": "^1.18.3",
    "debug": "^3.1.0",
    "dotenv": "^6.0.0",
    "express": "^4.16.3",
    "jsonwebtoken": "^8.3.0",
    "morgan": "^1.9.0",
    "multer": "^1.3.1",
    "mysql2": "^1.5.3",
    "nodemailer": "^4.6.7",
    "parse-error": "^0.2.0",
    "passport": "^0.4.0",
    "passport-jwt": "^4.0.0",
    "sequelize": "^4.37.10",
    "validator": "^10.4.0"
  }
}

.\\docker-compose.yml

version: '2'
services:
  api:
    build: .
    ports:
     - "4200:4200"
    depends_on:
     - db
    environment:
     - DATABASE_HOST=db
    volumes:
     - .:/usr/src/app
     - /usr/src/app/node_modules
  db:
    build: ./db

.\\Dockerfile

FROM node:8
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 4200
CMD [ "npm", "start" ]

.\\db\\Dockerfile

FROM mysql:latest

ENV MYSQL_ROOT_PASSWORD root  
ENV MYSQL_DATABASE test_dev  
ENV MYSQL_USER test-dev  
ENV MYSQL_PASSWORD testapi

I get the following error when I do "docker-compose up"- 当我执行“ docker-compose up”时,出现以下错误-

I'm pretty new to this, solution to solve this and few pointers on what to research more would help me a lot!

Try with this Dockerfile (avoid COPY *) and I recommend to use the absolute path in destination:

.\\Dockerfile

FROM node:8
COPY package.json /usr/src/app
WORKDIR /usr/src/app
RUN npm install
COPY . .
EXPOSE 4200
CMD [ "npm", "start" ]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM