0

我有一个简单的Dockerfile

FROM node:8

# Create app directory
WORKDIR /usr/src/app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./

RUN npm install
# If you are building your code for production
# RUN npm install --only=production

# Bundle app source
COPY . .

CMD ["npm", "run", "test"]

我在Google Cloud Build中运行它并获得以下日志:

...
Removing intermediate container 19ae183b28c6
 ---> 5802f218fa4e
Step 5/6 : COPY . .
 ---> a1600834b6e0
Step 6/6 : CMD npm run test
 ---> Running in bfb7be511b96
Removing intermediate container bfb7be511b96
 ---> 6e974d117670
Successfully built 6e974d117670
...

在步骤6/6, npm run test,我没有看到本地机器上的日志:

npm run test

 PASS  __tests__/order.spec.ts
 PASS  __tests__/news.spec.ts
 PASS  __tests__/product.spec.ts (5.328s)
 PASS  __tests__/review.spec.ts
 PASS  __tests__/donation.spec.ts
 PASS  __tests__/referral.spec.ts
 PASS  __tests__/nonprofit.spec.ts

Test Suites: 7 passed, 7 total
Tests:       22 passed, 22 total
Snapshots:   0 total
Time:        8.291s, estimated 9s

如何让这些日志显示在构建日志中?

4

1 回答 1

1

这是因为您正在构建图像而不是运行它:)。当您运行容器时,您将看到打印出的日志,例如

docker run -it my-image

于 2018-08-23T05:10:57.073 回答