我是第一次使用Docker和Docker-compose,我得到了这个错误ERROR: The Compose file is invalid because: Service volumes have neither an image nor a build context specified. At least one must be provided.,但是我的docker-compose文件有一个指定的构建上下文。我试着把build context移动到不同的地方,但仍然没有进展。这是我的docker-compose文件
version: '3.4'
services:
express:
container_name: express
image: node:12-alpine
volumes:
- type: bind
source: ./
target: /app
- type: volume
source: nodemodules
target: /app/node_modules
volume:
nocopy: true
build: .
working_dir: /app
command: npm run dev
ports:
- '4000:4000'
environment:
- NODE_ENV=development
- PORT=4000
volumes:
nodemodules:
links:
- mongo
mongo:
container_name: mongo
image: mongo
volumes:
- ./data:/data/db
ports:
- '27017:27017'
- '27018:27018'
- '27019:27019'我到底会做错什么呢?谢谢。
发布于 2020-10-23 23:53:28
发布于 2020-10-24 18:46:09
经过几天的搜索,我终于能够修复它了。很明显,我要做的就是把
volumes:
nodemodules:与文件的最后几行完全一样,并将它们从services映射中删除。所以我的文件在一天结束时变成了这个样子。
version: '3.4'
services:
express:
container_name: express
image: node:12-alpine
volumes:
- type: bind
source: ./
target: /app
- type: volume
source: nodemodules
target: /app/node_modules
volume:
nocopy: true
build: .
working_dir: /app
command: npm run dev
ports:
- '4000:4000'
environment:
- NODE_ENV=development
- PORT=4000
links:
- mongo
mongo:
container_name: mongo
image: mongo
volumes:
- ./data:/data/db
ports:
- '27017:27017'
- '27018:27018'
- '27019:27019'
volumes:
nodemodules:https://stackoverflow.com/questions/64276705
复制相似问题