我正在尝试重新排列我的项目结构。但是我的docker-compose文件出现了一些错误。
错误:
WARNING: The MONGO_USERNAME variable is not set. Defaulting to a blank string.
WARNING: The MONGO_PASSWORD variable is not set. Defaulting to a blank string.
WARNING: The MONGO_PORT variable is not set. Defaulting to a blank string.
WARNING: The MONGO_DB variable is not set. Defaulting to a blank string.
Recreating dcmapping2-server ... done
Starting db ... done
....
....
dcmapping2-server | npm ERR! path /home/node/app/package.json
dcmapping2-server | npm ERR! errno -2
dcmapping2-server | npm ERR! enoent ENOENT: no such file or directory, open '/home/node/app/package.json'
dcmapping2-server | npm ERR! enoent This is related to npm not being able to find a file.
dcmapping2-server | npm ERR! enoent
我的项目的组织方式如下:(在src中,有一个nodejs后端和一个react前端)。
服务器Dockerfile
如下:
FROM node:12-alpine
RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app
WORKDIR /home/node/app
COPY package*.json ./
RUN apk --no-cache add --virtual builds-deps build-base python
USER node
RUN npm install
COPY --chown=node:node . .
EXPOSE 8080
CMD ["npm", "run", "start"]
我的docker-compose.yml
如下:
version: '3'
services:
nodejs:
build:
context: ../../src/server
dockerfile: Dockerfile
image: dcmapping2-server
container_name: dcmapping2_server
restart: unless-stopped
env_file: ../environment/.env.prod.server
environment:
- NODE_ENV=docker
- MONGO_USERNAME=$MONGO_USERNAME
- MONGO_PASSWORD=$MONGO_PASSWORD
- MONGO_HOSTNAME=db
- MONGO_PORT=$MONGO_PORT
- MONGO_DB=$MONGO_DB
ports:
- "5055:8080"
volumes:
- .:/home/node/app
- node_modules:/home/node/app/node_modules
networks:
- app-network
db:
image: mongo:4.2.3-bionic
container_name: db
restart: unless-stopped
env_file: ../environment/.env.prod.server
environment:
- MONGO_INITDB_ROOT_USERNAME=$MONGO_USERNAME
- MONGO_INITDB_ROOT_PASSWORD=$MONGO_PASSWORD
ports:
- "28017-28019:27017-27019"
volumes:
- dbdata:/data/db
networks:
- app-network
networks:
app-network:
driver: bridge
volumes:
dbdata:
node_modules:
此文件尚不完整,但在此步骤中,服务器应正常运行。
我阅读了一些有关卷错误的答案,但是那里的答案对我没有帮助。
谢谢。