docker-compose.yml问题nodejs和mysql

时间:2018-07-05 09:01:33

标签: mysql node.js docker docker-compose dockerfile

我试图将我的nodeJS api码头化。检出以下文件:

。\ 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

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

我对此还很陌生,解决该问题的解决方案以及关于需要研究的内容的几点建议对我有很大帮助!

1 个答案:

答案 0 :(得分:0)

尝试使用此Dockerfile(避免COPY *),我建议在目标位置使用绝对路径:

。\ Dockerfile

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