我正在尝试使用 docker compose 文件设置节点 15.3.2 版本。我已经在 dockerfile 中添加了所有必要的要求。但是执行
docker compose up
命令后,我面临以下错误。我也尝试了 docker compose --build
命令。如果有人有任何解决方案请告诉我。
Dockerfile
FROM node:15-alpine3.10
WORKDIR /var/apps/frontend
COPY frontend /var/apps/frontend/
RUN apk update
RUN apk add alpine-sdk
RUN apk add --update npm
RUN apk add --update python3 make g++ && rm -rf /var/cache/apk/*
RUN npm install -g [email protected]
RUN rm -rf node_modules
RUN npm cache clean --force
RUN npm rebuild node-sass --force
RUN npm i [email protected] --legacy-peer-deps
RUN npm install --legacy-peer-deps
CMD [ "npm", "start" ]
docker-compose.yml
frontend:
build:
context: .
dockerfile: ./docker/frontend/Dockerfile
container_name: ui
command: bash -c "npm config set package-lock false && npm install && yarn run docker"
networks: ['ao_platform_network']
depends_on: ['django']
ports:
- "8081:8081"
environment:
- RAILS_ENV=development
- RAKE_ENV=development
- NODE_ENV=development
volumes:
- type: bind
source: ./frontend
target: /var/apps/frontend
错误:
node:internal/modules/cjs/loader:927
throw err;
^
Error: Cannot find module '/var/apps/frontend/bash'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15)
at Function.Module._load (node:internal/modules/cjs/loader:769:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
at node:internal/main/run_main_module:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
默认情况下,
bash
不包含在 Alpine Linux
中。所以,你需要在 Dockerfile 中添加这个命令:
RUN apk update && apk add bash
但请注意,仅添加此内容就足够了:
RUN apk add bash
您还可以添加
--no-cache
选项以避免将下载的包保留在缓存中:
RUN apk add --no-cache bash