mirror of
https://github.com/goldbergyoni/nodebestpractices.git
synced 2025-10-30 17:17:03 +08:00
style: set dockerfile markdown snippet to highlight accordingly
This commit is contained in:
@ -15,7 +15,7 @@ A Docker image isn't just a bunch of files but rather multiple layers revealing
|
|||||||
|
|
||||||
<summary><strong>Dockerfile</strong></summary>
|
<summary><strong>Dockerfile</strong></summary>
|
||||||
|
|
||||||
```
|
```dockerfile
|
||||||
# syntax = docker/dockerfile:1.0-experimental
|
# syntax = docker/dockerfile:1.0-experimental
|
||||||
|
|
||||||
FROM node:12-slim
|
FROM node:12-slim
|
||||||
@ -36,19 +36,23 @@ RUN --mount=type=secret,id=npm,target=/root/.npmrc npm ci
|
|||||||
|
|
||||||
<summary><strong>Dockerfile</strong></summary>
|
<summary><strong>Dockerfile</strong></summary>
|
||||||
|
|
||||||
```
|
```dockerfile
|
||||||
|
|
||||||
FROM node:12-slim AS build
|
FROM node:12-slim AS build
|
||||||
|
|
||||||
ARG NPM_TOKEN
|
ARG NPM_TOKEN
|
||||||
|
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
COPY . /dist
|
COPY . /dist
|
||||||
|
|
||||||
RUN echo "//registry.npmjs.org/:\_authToken=\$NPM_TOKEN" > .npmrc && \
|
RUN echo "//registry.npmjs.org/:\_authToken=\$NPM_TOKEN" > .npmrc && \
|
||||||
npm ci --production && \
|
npm ci --production && \
|
||||||
rm -f .npmrc
|
rm -f .npmrc
|
||||||
|
|
||||||
|
|
||||||
FROM build as prod
|
FROM build as prod
|
||||||
|
|
||||||
COPY --from=build /dist /dist
|
COPY --from=build /dist /dist
|
||||||
CMD ["node","index.js"]
|
CMD ["node", "index.js"]
|
||||||
|
|
||||||
# The ARG and .npmrc won't appear in the final image but can be found in the Docker daemon un-tagged images list - make sure to delete those
|
# The ARG and .npmrc won't appear in the final image but can be found in the Docker daemon un-tagged images list - make sure to delete those
|
||||||
```
|
```
|
||||||
@ -63,19 +67,21 @@ CMD ["node","index.js"]
|
|||||||
|
|
||||||
<summary><strong>Dockerfile</strong></summary>
|
<summary><strong>Dockerfile</strong></summary>
|
||||||
|
|
||||||
```
|
```dockerfile
|
||||||
|
|
||||||
FROM node:12-slim
|
FROM node:12-slim
|
||||||
|
|
||||||
ARG NPM_TOKEN
|
ARG NPM_TOKEN
|
||||||
|
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
COPY . /dist
|
COPY . /dist
|
||||||
|
|
||||||
RUN echo "//registry.npmjs.org/:\_authToken=\$NPM_TOKEN" > .npmrc && \
|
RUN echo "//registry.npmjs.org/:\_authToken=\$NPM_TOKEN" > .npmrc && \
|
||||||
npm ci --production && \
|
npm ci --production && \
|
||||||
rm -f .npmrc
|
rm -f .npmrc
|
||||||
|
|
||||||
# Deleting the .npmrc within the same copy command will not save it inside the layer, however it can be found in image history
|
# Deleting the .npmrc within the same copy command will not save it inside the layer, however it can be found in image history
|
||||||
|
|
||||||
CMD ["node","index.js"]
|
CMD ["node", "index.js"]
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|||||||
Reference in New Issue
Block a user