我试图将docker添加到我的项目中。目录结构如下:
proj
|_ app
| |_ project
| |_ api
| |_ frontend
| |_ src
| | |_ index.js
| |_ static
| |_ templates
|__ Dockerfile
|__ docker-compose.yml
|__ package.json
docker-compose.yml
如下:
version: '3'
services:
db:
image: postgres
web:
container_name: api
build: .
command: python ./app/manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
- front
front:
container_name: front
build: .
command: npm run dev
volumes:
- .:/code
ports:
- "3000:3000"
Dockerfile
:
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN apt-get update && apt-get -y install build-essential curl
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -
RUN apt-get install -y nodejs
RUN nodejs -v && npm -v
RUN mkdir /code
WORKDIR /code
COPY app/requirements.txt /code/
COPY package.json /code
COPY . /code/
RUN pip install -r requirements.txt
RUN npm cache clean
RUN npm install
RUN npm run dev
RUN python app/manage.py makemigrations
RUN python app/manage.py migrate
和package.json
:
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "webpack.config.js",
"scripts": {
"start": "npm run dev",
"dev": "webpack --mode development ./project/frontend/src/index.js --output ./project/frontend/static/frontend/main.js",
"build": "webpack --mode production ./project/frontend/src/index.js --output ./project/frontend/static/frontend/main.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.2.2",
"@babel/preset-env": "^7.3.1",
"@babel/preset-react": "^7.0.0",
"babel-loader": "^8.0.5",
"babel-plugin-transform-class-properties": "^6.24.1",
"prop-types": "^15.6.2",
"react": "^16.8.0",
"react-dom": "^16.8.0",
"react-scripts": "1.1.0",
"webpack": "^4.29.1",
"webpack-cli": "^3.2.3"
},
"dependencies": {
"babel-polyfill": "^6.26.0"
}
}
和errors
我得到了:
ERROR in Entry module not found: Error: Can't resolve './project/frontend/src/index.js' in '/code'
npm ERR! Linux 4.18.0-15-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "run" "dev"
npm ERR! node v6.16.0
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! app@1.0.0 dev: `webpack --mode development ./project/frontend/src/index.js --output ./project/frontend/static/frontend/main.js`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the app@1.0.0 dev script 'webpack --mode development ./project/frontend/src/index.js --output ./project/frontend/static/frontend/main.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the app package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! webpack --mode development ./project/frontend/src/index.js --output ./project/frontend/static/frontend/main.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs app
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls app
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /code/npm-debug.log
ERROR: Service 'front' failed to build: The command '/bin/sh -c npm run dev' returned a non-zero code: 1
Error: Can't resolve './project/frontend/src/index.js' in '/code'
我尝试将路径更改为./app/project/frontend/src/index.js
,但仍然遇到相同的错误。
我不知道该如何调试,以及如何弄清楚路径出了什么问题。也许我没看到什么?可以在Docker方面有经验的人看看并告诉我哪里出了问题吗?