问题
Below is the dockerfile which is stored as image tag somehub/someapp-specs
:
FROM ubuntu:trusty
MAINTAINER Developer team <developerteam@abc.com>
# Prevent dpkg source
ENV TERM=xterm-256color
# Set mirrors to ca
RUN sed -i "s/http:\/\/archive./http:\/\/ca.archive./g" /etc/apt/sources.list
# Install node.js
RUN apt-get update && \
apt-get install curl -y && \
curl -sL http://deb.nodesource.com/setup_4.x | sudo -E bash - && \
apt-get install -y nodejs
COPY . /app
WORKDIR /app
# Install application dependencies
RUN npm install -g mocha && \
npm install
# Set mocha test runner as entrypoint
ENTRYPOINT ["mocha"]
which is used in test
service in below snipper of docker-compose:
test:
image: somehub/someapp-specs
links:
- nginx
environment:
URL: http://nginx:8080/todos
JUNIT_REPORT_PATH: /reports/acceptance.xml
JUNIT_REPORT_STACK: 1
command: --reporter mocha-jenkins-reporter
that launched mocha
container with error:
$ docker-compose up test
release_dbc_1 is up-to-date
Starting release_webroot_1 ... done
Creating release_app_1 ... done
Creating release_nginx_1 ... done
Creating release_test_1 ... done
Attaching to release_test_1
test_1 | /usr/lib/node_modules/mocha/bin/mocha:13
test_1 | const {deprecate, warn} = require('../lib/utils');
test_1 | ^
test_1 |
test_1 | SyntaxError: Unexpected token {
test_1 | at exports.runInThisContext (vm.js:53:16)
test_1 | at Module._compile (module.js:373:25)
test_1 | at Object.Module._extensions..js (module.js:416:10)
test_1 | at Module.load (module.js:343:32)
test_1 | at Function.Module._load (module.js:300:12)
test_1 | at Function.Module.runMain (module.js:441:10)
test_1 | at startup (node.js:140:18)
test_1 | at node.js:1043:3
release_test_1 exited with code 1
COPY . /app
instruction in Dockerfile is copying package.json with below versions:
{
"name": "someappspecs",
"version": "0.1.0",
"description": "someapp acceptance tests",
"main": "app.js",
"scripts": {
"test": "mocha"
},
"author": "xyz",
"license": "ISC",
"dependencies": {
"bluebird": "^3.7.0",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"mocha": "^6.2.1",
"mocha-jenkins-reporter": "^0.4.2",
"superagent": "^5.1.0",
"superagent-promise": "^1.1.0"
}
}
mocha
is used to run acceptance tests on release_app_1
container
How to resolve this unexpected token error? looks unrelated with other container service.
回答1:
That's because Mocha require node >6.0 but yours 4.x
As of v6.0.0, Mocha requires Node.js v6.0.0 or newer.
Try to upgrade your node by using Node image:
FROM node:10.16
or you can update your current dockerfile like so:
RUN apt-get update && \
apt-get install curl -y && \
curl -sL https://deb.nodesource.com/setup_10.x | bash - && \
apt-get install -y nodejs
来源:https://stackoverflow.com/questions/58479409/dockerfile-unexpected-token-error-in-mocha