我有这项docker
服务:
client/
.dockerignore
Dockerfile-dev
package.json
node_modules/
react-router-dom/
spotify-web-api-js/
and-many-more/
src/
App.jsx
Spotify.js
将安装以下node
个模块:
package.json
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"axios": "^0.18.0",
"react": "^16.8.2",
"react-dom": "^16.8.2",
"react-router-dom": "^4.3.1",
"react-scripts": "2.1.5",
"spotify-web-api-js": "^0.22.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
],
"devDependencies": {
"enzyme": "^3.8.0",
"enzyme-adapter-react-16": "^1.7.1"
}
}
像这样:
Dockerfile-dev
# base image
FROM node:11.6.0-alpine
# set working directory
WORKDIR /usr/src/app
# add `/usr/src/app/node_modules/.bin` to $PATH
ENV PATH /usr/src/app/node_modules/.bin:$PATH
# install and cache app dependencies
COPY package.json /usr/src/app/package.json
RUN npm install --silent
RUN npm install react-scripts@2.1.2 -g --silent
# start app
CMD ["npm", "start"]
在同一路径src
上,但是我观察到两种不同的行为:
1)可行:
App.jsx
import React, { Component } from 'react';
import { Route, Switch } from 'react-router-dom';
2),但这不起作用:
Spotify.js
import React, { Component } from 'react';
import SpotifyWebApi from 'spotify-web-api-js';
引发以下错误:
Failed to compile
./src/Spotify.js
Module not found: Can't resolve 'spotify-web-api-js' in '/usr/src/app/src'
docker-compose-dev.yml
client:
build:
context: ./services/client
dockerfile: Dockerfile-dev
volumes:
- './services/client:/usr/src/app'
- '/usr/src/app/node_modules'
ports:
- 3007:3000
environment:
- NODE_ENV=development
- REACT_APP_WEB_SERVICE_URL=${REACT_APP_WEB_SERVICE_URL}
depends_on:
- web
.dockerignore
node_modules
coverage
build
env
htmlcov
.dockerignore
Dockerfile-dev
Dockerfile-prod
我想念什么?
答案 0 :(得分:1)
希望这有助于为我工作的人奔跑
docker-compose down -v
它将删除所有卷。