3
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Dockerfileでヒアドキュメントが使えるようになった

Posted at

アナウンス記事

リファレンス

従来のDockerfile

公式のベストプラクティスに従って、複数のapt-getを&&で繋いで一つのRUNに収めています。

Dockerfile.slim
FROM node:slim
RUN apt-get update && apt-get install -y \
    tini \
 && apt-get clean \
 && rm -rf /var/lib/apt/lists/*
ENTRYPOINT ["/usr/bin/tini", "--"]
USER node
WORKDIR /home/node
COPY --chown=node:node package.json package-lock.json ./
RUN npm install --production && npm cache clean --force
COPY --chown=node:node index.ts ./
CMD ["node_modules/.bin/ts-node", "index.ts"]

これからのDockerfile

複数のapt-getを書く箇所がヒアドキュメントを使ってより見やすく書くことができるようになりました。
現時点では、先頭に# syntax=docker/dockerfile:1.3-labsが必要な点と、エディタのシンタックスハイライトが対応していない場合があるという点で注意が必要です。

Dockerfile.slim
# syntax=docker/dockerfile:1.3-labs
FROM node:slim
RUN <<eot
apt-get update
apt-get install -y \
  tini
apt-get clean
rm -rf /var/lib/apt/lists/*
eot
ENTRYPOINT ["/usr/bin/tini", "--"]
USER node
WORKDIR /home/node
COPY --chown=node:node package.json package-lock.json ./
RUN npm install --production && npm cache clean --force
COPY --chown=node:node index.ts ./
CMD ["node_modules/.bin/ts-node", "index.ts"]

わかりやすい差分

3
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?