我的docker构建可以在我的设备上运行。当我上传到digital-ocean服务器并执行"docker-compose up -d“命令时,除了”前端“,所有的容器都启动了。问题出在“卷”上,当我删除它时,一切都正常。如何解决这个问题?我需要这份财产保留下来。
frontend_1 | > test-docker@0.1.0 dev /app/client
frontend_1 | > next dev
frontend_1 |
frontend_1 | sh: 1: next: not found
frontend_1 | npm ERR! code ELIFECYCLE
frontend_1 | npm ERR! syscall spawn
frontend_1 | npm ERR! file sh
frontend_1 | npm ERR! errno ENOENT
frontend_1 | npm ERR! test-docker@0.1.0 dev: `next dev`
frontend_1 | npm ERR! spawn ENOENT
frontend_1 | npm ERR!
frontend_1 | npm ERR! Failed at the test-docker@0.1.0 dev script.
frontend_1 | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
frontend_1 | npm WARN Local package.json exists, but node_modules missing, did you mean to install?
frontend_1 |
frontend_1 | npm ERR! A complete log of this run can be found in:
frontend_1 | npm ERR! /root/.npm/_logs/2021-01-31T01_14_30_246Z-debug.logdocker-compose.yml:
version: "3.8"
services:
api:
restart: always
ports:
- 8081:8081
build:
context: ./server
dockerfile: ./Dockerfile
volumes:
- ./server:/app/server
command: npm run dev
depends_on:
- mongo
frontend:
restart: always
ports:
- 3000:3000
build:
context: ./client
dockerfile: ./Dockerfile
volumes:
- ./client:/app/client
depends_on:
- api
mongo:
image: mongo
expose:
- 27017
ports:
- 27017:27017
volumes:
- apiDB:/data/db
volumes:
apiDB:
version: "3.8"
services:
api:
restart: always
ports:
- 8081:8081
build:
context: ./server
dockerfile: ./Dockerfile
volumes:
- ./server:/app/server
command: npm run dev
depends_on:
- mongo
frontend:
restart: always
ports:
- 3000:3000
build:
context: ./client
dockerfile: ./Dockerfile
volumes:
- ./client:/app/client
depends_on:
- api
mongo:
image: mongo
expose:
- 27017
ports:
- 27017:27017
volumes:
- apiDB:/data/db
volumes:
apiDB:./client/Dockerfile:
FROM node:14
RUN mkdir -p /app/client
WORKDIR /app/client
COPY . /app/client
RUN npm install
CMD [ "npm", "run", "dev"]发布于 2021-02-02 01:05:54
我不建议您使用镜像的构建上下文(例如build: context: ./client)与容器的卷挂载(例如volumes: ./client:${SOMETHING})相同,这可能是问题所在。
本地主机上的构建上下文用于构建映像,并将其COPY到映像的/app/client目录。
运行映像时,您会尝试将(以前复制到映像的)目录(/app/client)替换为快捷批处理上现在为空的目录。
如果您的Dockerfile是正确的(并且复制了本地主机的./client ),那么您可以丢弃frontend的volume挂载(因为它已经在/app/client下)。
https://stackoverflow.com/questions/65975992
复制相似问题