[英]nuxt: not found inside docker image
我正在為 nuxt 3 應用程序構建 docker 環境。 這是我的package.json
文件:
{
"private": true,
"scripts": {
"start": "nuxt start",
"build": "nuxt build",
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview",
"prepare": "husky install",
"prepare:hook": "husky add .husky/commit-msg \"npx --no -- commitlint --edit $1"
},
"dependencies": {
"nuxt": "3.0.0-rc.6"
},
"devDependencies": {
"@commitlint/cli": "^17.0.3",
"@commitlint/config-conventional": "^17.0.3",
"@commitlint/types": "^17.0.0",
"@formkit/nuxt": "1.0.0-beta.9",
"@formkit/themes": "1.0.0-beta.9",
"@formkit/vue": "1.0.0-beta.9",
"@nuxt/kit": "npm:@nuxt/kit-edge@latest",
"@pinia/nuxt": "^0.3.0",
"@swisscom/sdx": "file:./sdx",
"@typescript-eslint/eslint-plugin": "^5.30.5",
"@typescript-eslint/parser": "^5.30.5",
"eslint": "^8.19.0",
"eslint-plugin-nuxt": "^3.2.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-vue": "^9.2.0",
"husky": "^8.0.1",
"luxon": "^3.0.1",
"pinia": "^2.0.16",
"prettier": "2.7.1",
"sass": "^1.53.0",
"typescript": "^4.7.4",
"vue": "^3.2.37"
}
}
這是我的docker-compose.yml
文件:
services:
app:
build:
context: .
dockerfile: Dockerfile
args:
- NPM_TOKEN=${NPM_TOKEN}
- NPM_MAIL=${NPM_MAIL}
restart: always
ports:
- '3000:3000'
env_file:
- .env
depends_on:
- db
db:
image: mongo
restart: always
ports:
- 27017:27017
volumes:
- smap_db:/usr/db/smap
environment:
MONGO_INITDB_ROOT_USERNAME: ${DB_USER}
MONGO_INITDB_ROOT_PASSWORD: ${DB_PASSWORD}
volumes:
smap_db:
external: true
這是我的Dockerfile
3 應用程序的 Dockerfile:
# Dockerfile
FROM node:18.6.0-bullseye
ARG NPM_TOKEN
ARG NPM_MAIL
# Set working directory
WORKDIR /usr/bin/smap
# Install dependencies
COPY .npmrc package.json sdx ./
RUN npm install
RUN rm -f .npmrc
# Copy the app
COPY . .
RUN npm run build
EXPOSE 3000
ENV NUXT_HOST=0.0.0.0
CMD [ "npm", "start" ]
這是我的.dockerignore
文件:
# Dependencies
node_modules
# Editor
.vscode
# Build outputs
.nuxt
.output
dist
# Commitlint
.husky
commitlint.config.ts
# Other
README.md
當我運行docker compose up
我在構建 docker 文件時收到以下錯誤:
=> ERROR [7/7] RUN npm run build 0.8s
------
> [7/7] RUN npm run build:
#0 0.796
#0 0.796 > build
#0 0.796 > nuxt build
#0 0.796
#0 0.803 /tmp/build6594337338.sh: 2: nuxt: not found
------
failed to solve: executor failed running [/bin/sh -c npm run build]: exit code: 127
這是我迄今為止嘗試解決的問題:
.dockerignore
中的所有內容node:18.6.0-bullseye
node:18.6.0
node:18.6.0-alpine
node:18
所有這些都沒有幫助,我總是遇到同樣的錯誤。
為什么在 docker 容器內找不到nuxt
命令? 難道我做錯了什么? 有誰知道我該如何解決這個問題?
我將NPM_CONFIG_LOGLEVEL
設置為info
。 錯誤仍然相同,但有一些附加信息:
=> ERROR [8/8] RUN npm run build 1.7s
------
> [8/8] RUN npm run build:
#0 1.641 npm info using npm@8.15.0
#0 1.642 npm info using node@v18.7.0
#0 1.642 npm timing npm:load:whichnode Completed in 0ms
#0 1.643 npm timing config:load:defaults Completed in 2ms
#0 1.643 npm timing config:load:file:/usr/local/lib/node_modules/npm/npmrc Completed in 5ms
#0 1.643 npm timing config:load:builtin Completed in 6ms
#0 1.643 npm timing config:load:cli Completed in 1ms
#0 1.644 npm timing config:load:env Completed in 1ms
#0 1.644 npm timing config:load:file:/usr/bin/smap/.npmrc Completed in 2ms
#0 1.644 npm timing config:load:project Completed in 5ms
#0 1.644 npm timing config:load:file:/root/.npmrc Completed in 0ms
#0 1.644 npm timing config:load:user Completed in 1ms
#0 1.645 npm timing config:load:file:/usr/local/etc/npmrc Completed in 6ms
#0 1.645 npm timing config:load:global Completed in 6ms
#0 1.645 npm timing config:load:validate Completed in 2ms
#0 1.645 npm timing config:load:credentials Completed in 1ms
#0 1.645 npm timing config:load:setEnvs Completed in 1ms
#0 1.645 npm timing config:load Completed in 28ms
#0 1.645 npm timing npm:load:configload Completed in 28ms
#0 1.645 npm timing npm:load:mkdirpcache Completed in 1ms
#0 1.645 npm timing npm:load:mkdirplogs Completed in 1ms
#0 1.645 npm timing npm:load:setTitle Completed in 1ms
#0 1.646 npm timing config:load:flatten Completed in 2ms
#0 1.646 npm timing npm:load:display Completed in 9ms
#0 1.653 npm timing npm:load:logFile Completed in 7ms
#0 1.653 npm timing npm:load:timers Completed in 0ms
#0 1.654 npm timing npm:load:configScope Completed in 0ms
#0 1.656 npm timing npm:load Completed in 50ms
#0 1.667
#0 1.667 > build
#0 1.667 > nuxt build
#0 1.667
#0 1.675 /tmp/build-27aedcc8.sh: 1: nuxt: not found
#0 1.677 npm timing command:run Completed in 15ms
#0 1.678 npm timing npm Completed in 74ms
------
failed to solve: executor failed running [/bin/sh -c npm run build]: exit code: 127
Sooo,這對我來說是一個虛幻的時刻。 感謝這個評論,我能夠解決這個問題。 在我的 dockerfile 上,我有這行代碼COPY.npmrc package.json sdx./
。 Sdx 是我公司的內部 package,在這個項目中,我使用它來測試一些仍在生產模式下開發的新功能,這就是 docker 容器的原因。 This package of course has a package.json
and this one overwrote my package.json
. 我只是從COPY
命令中刪除了sdx
,並在之后的行中為sdx
創建了一個新的COPY
。 COPY./sdx./sdx
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.