我正在尝试运行docker-compose.yml文件。代码如下:
docker-compose.yml
# Install node v10
FROM node:10.16.3
# Set the workdir /var/www/myapp
WORKDIR /var/www/myapp
# Copy the package.json to workdir
COPY package.json ./
# Run npm install - install the npm dependencies
RUN npm install
# Copy application source
COPY . .
# Copy .env.docker to workdir/.env - use the docker env
COPY .env.docker ./.env
# Expose application ports - (4300 - for API and 4301 - for front end)
# EXPOSE 4300 4301
EXPOSE 8080
# Generate build
#RUN npm run build
# Start the application
#CMD ["npm", "run", "run:prod"]
CMD [ "npm", "start" ]
我收到错误消息“这可能不是npm的问题。上面可能还有其他日志记录输出”。以下是我的错误日志。
Step 4/8 : RUN npm install
---> Running in 411661ac5c9f
npm WARN deprecated superagent@3.8.3: Please note that v5.0.1+ of superagent removes User-Agent header by default, therefore you may need to add it yourself (e.g. GitHub blocks requests without a User-Agent header). This notice will go away with v5.0.2+ once it is released.
npm WARN deprecated boom@7.3.0: This module has moved and is now available at @hapi/boom. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
npm WARN deprecated left-pad@1.3.0: use String.prototype.padStart()
npm WARN deprecated hoek@6.1.3: This module has moved and is now available at @hapi/hoek. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
> java@0.11.1 install /var/www/myapp/node_modules/java
> node-gyp rebuild
[node-java] Error: not found: javac
gyp: Call to 'node findJavaHome.js' returned exit status 1 while in binding.gyp. while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:345:16)
gyp ERR! stack at ChildProcess.emit (events.js:198:13)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)
gyp ERR! System Linux 4.9.184-linuxkit
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /var/www/myapp/node_modules/java
gyp ERR! node -v v10.16.3
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.0.7 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.0.7: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! java@0.11.1 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the java@0.11.1 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2019-09-09T11_31_39_551Z-debug.log
ERROR: Service 'myapp' failed to build: The command '/bin/sh -c npm install' returned a non-zero code: 1
如何解决上述错误错误?
我正在尝试通过使用以下命令来运行: docker-compose up
答案 0 :(得分:1)
如果看到错误,则表明node-gyp无法找到Java:Error: not found: javac
。
您需要通过更新Dockerfile来安装jdk,以包括如下命令:
# Install node v10
FROM node:10.16.3
RUN apt update && apt install -y openjdk-8-jdk