请不要将此标记为重复。我知道我之前曾问过这个问题,但是我的问题没有得到解决。
在构建镜像之前,我已经尝试过将RUN npm install --save-dev react-dev-utils添加到dockerfile中,但这不能解决问题。
吊舱日志
> wootz@0.1.0 start /usr/src/app
> node scripts/start.js
internal/modules/cjs/loader.js:626
throw err;
^
Error: Cannot find module 'react-dev-utils/chalk'
Require stack:
- /usr/src/app/scripts/start.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:623:15)
at Function.Module._load (internal/modules/cjs/loader.js:527:27)
at Module.require (internal/modules/cjs/loader.js:681:19)
at require (internal/modules/cjs/helpers.js:16:16)
at Object.<anonymous> (/usr/src/app/scripts/start.js:19:15)
at Module._compile (internal/modules/cjs/loader.js:774:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
at Module.load (internal/modules/cjs/loader.js:641:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:837:10) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/usr/src/app/scripts/start.js' ]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! wootz@0.1.0 start: `node scripts/start.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the wootz@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional log ging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2019-06-17T15_56_02_649Z-debug.log
uipersistantvolume
kind: PersistentVolume
apiVersion: v1
metadata:
name: ui-initdb-pv-volume
labels:
type: local
app: ui
spec:
storageClassName: manual
capacity:
storage: 1Mi
accessModes:
- ReadOnlyMany
hostPath:
path: "/home/vignesh/pagedesigneryamls/client"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: ui-initdb-pv-claim-one
labels:
app: ui
spec:
storageClassName: manual
accessModes:
- ReadOnlyMany
resources:
requests:
storage: 1Mi
uipersistantvolumetwo
kind: PersistentVolume
apiVersion: v1
metadata:
name: ui-initdb-pv-volume-two
labels:
type: local
app: ui
spec:
storageClassName: manual
capacity:
storage: 1Mi
accessModes:
- ReadOnlyMany
hostPath:
path: "/home/vignesh/pagedesigneryamls/client"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: ui-initdb-pv-claim-two
labels:
app: ui
spec:
storageClassName: manual
accessModes:
- ReadOnlyMany
resources:
requests:
storage: 1Mi
ui.yaml
apiVersion: v1
kind: Service
metadata:
name: ui
labels:
app: ui
spec:
ports:
- name: myport
port: 80
targetPort: 3000
selector:
app: ui
tier: frontend
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: ui
labels:
app: ui
spec:
selector:
matchLabels:
app: ui
tier: frontend
strategy:
type: Recreate
template:
metadata:
labels:
app: ui
tier: frontend
spec:
containers:
- image: suji165475/devops-sample:updatedclientdockerfile
name: ui
ports:
- containerPort: 80
name: myport
volumeMounts:
- name: ui-persistent-storage-one
mountPath: /usr/src/app
- name: ui-persistent-storage-two
mountPath: /usr/src/app/node_modules
volumes:
- name: ui-persistent-storage-one
persistentVolumeClaim:
claimName: ui-initdb-pv-claim-one
- name: ui-persistent-storage-two
persistentVolumeClaim:
claimName: ui-initdb-pv-claim-two
ui yaml中使用的图像是使用以下dockerfile构建的
FROM node:12.4.0-alpine
RUN mkdir -p usr/src/app
WORKDIR /usr/src/app
COPY package.json package.json
RUN npm install && npm cache clean --force
RUN npm install -g webpack-cli
RUN npm install --save-dev react-dev-utils
WORKDIR /usr/src/app
COPY . .
WORKDIR /usr/src/app
EXPOSE 3000
RUN npm run build
CMD [ "npm","start" ]
docker-compose.yaml
version: "3"
services:
pg_db:
image: postgres
networks:
- wootzinternal
ports:
- 5432
environment:
- POSTGRES_PASSWORD=password
- POSTGRES_USER=postgres
- POSTGRES_DB=wootz
volumes:
- wootz-db:/var/lib/postgresql/data
apiserver:
image: wootz-backend
volumes:
- ./api:/usr/src/app
- /usr/src/app/node_modules
build:
context: ./api
dockerfile: Dockerfile
networks:
- wootzinternal
depends_on:
- pg_db
ports:
- '8000:8000'
ui:
image: wootz-frontend
volumes:
- ./client:/usr/src/app
- /usr/src/app/build
- /usr/src/app/node_modules
build:
context: ./client
dockerfile: Dockerfile
networks:
- wootzinternal
ports:
- '80:3000'
volumes:
wootz-db:
networks:
wootzinternal:
driver: bridge
我该如何解决错误找不到模块'react-dev-utils / chalk'? dockerfile中缺少任何内容吗?还是我应该删除任何东西?
注意:当使用docker run命令直接作为容器运行时或使用docker-compose时,ui应用程序运行完美,但是在kubernetes上运行时会显示此错误。请帮助
答案 0 :(得分:0)
不要将卷挂载在容器文件所在的同一位置。
是的,它可以与 docker 一起使用。是的,它可以与 docker-compose 一起使用。
但你必须意识到 kubernetes 处理卷的方式与 docker/docker-compose 不同
K8s 以类似于 bind mount in docker 的方式挂载卷。例如,这意味着 k8s 卷不会预先填充位于卷安装路径下的容器内容。如果您在 /usr/src/app
下挂载一个卷,放置在那里的每个文件现在都消失了(或者由于绑定挂载而隐藏了)并且无法轻松访问。
那么在这种情况下你能做什么呢?重新考虑您的应用程序设计,最重要的是:不要将您的卷安装在您保存文件的地方(例如本例中的模块文件)。挂载卷时,选择容器中不存在的路径,或者存在且为空的路径。