NAPOAN.COM by マイクラ思考 
/ UPDATE :

MacでDocker.raw周辺だけ外付けドライブに置くとビルド速度は変わるか

Sというドライブをマウントしたとする。

mkdir -p /Volumes/S/Docker/Data/vms
ln -s /Volumes/S/Docker/Data/vms ~/Library/Containers/com.docker.docker/Data

これで/Volumes/S/Docker/Data/vms/0/dataに巨大なDocker.rawが置かれるが、Docker Desktopのデータは元の場所に残る。

vms以外は恐ろしくて触れないので放置。

ビルド時間比較

node:12-slimを2ステージに分けて、「Node.jsのパッケージをインストール、node_modulesだけ別ステージにコピー」「ランナーステージではChromeを入れてTypeScriptをビルド」という長ったらしいことをしている。なぜこんな大量にライブラリを入れているかとというと、Cloud Runでpuppetterを使うため。

Dockerfile

# 参考: https://qiita.com/YusukeIwaki/items/37c5e7be3fe1116c60ec
# https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#chrome-headless-doesnt-launch-on-unix
# -------------------------------------------------------

FROM --platform=amd64 node:12-slim AS deps
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn install

# -------------------------------------------------------
FROM --platform=amd64 node:12-slim AS runner
WORKDIR /app
# libcurl3-gnutlsが上記にないが足りなかったので追記
RUN apt-get update 
    && apt-get install -y ca-certificates libappindicator3-1 libxss1 
    libasound2 libatk-bridge2.0-0 libatk1.0-0 libc6 libcairo2 libcups2 
    libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libglib2.0-0 
    libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 
    libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 
    libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxtst6 
    lsb-release wget xdg-utils libcurl3-gnutls 
    --no-install-recommends

# fonts-liberationが必須、fonts-noto-cjkを実際に使う
RUN apt update 
    && apt-get install -y fonts-liberation fonts-noto-cjk 
      --no-install-recommends
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN dpkg --configure -a 
    && apt install -f 
    && dpkg -i ./google-chrome-stable_current_amd64.deb

COPY --from=deps /app/node_modules ./node_modules

# 本来はこのようにTypeScriptのビルドをするが、
# ここの時間はソースコードに依存するためカット
# COPY ./src ./src
# COPY ./tsconfig.json ./package.json ./
#
# RUN yarn build
# CMD ["yarn", "start"]
CMD ["echo", "DONE"]

TypeScriptのトランスコンパイル時間はソースコードに依存するためカット。

package.json

{
  "name": "og-image",
  "version": "0.0.1",
  "license": "MIT",
  "scripts": {
    "build": "tsc",
    "dev": "concurrently "tsc -w" "nodemon --watch ./build/ --exec NODE_ENV=development PORT=3002 yarn start"",
    "start": "node build/index.js",
    "local:debug": "yarn build && OG_HTML_DEBUG=1 node build/index.js"
  },
  "dependencies": {
    "express": "4.17.1",
    "marked": "2.0.0",
    "puppeteer-core": "7.0.0",
    "twemoji": "13.0.1"
  },
  "devDependencies": {
    "@types/express": "^4.17.1",
    "@types/marked": "1.2.2",
    "@types/node": "^17.0.0",
    "@types/puppeteer": "5.4.3",
    "@types/puppeteer-core": "5.4.0",
    "@types/twemoji": "^12.1.2",
    "concurrently": "^6.5.1",
    "nodemon": "^2.0.15",
    "ts-node": "^10.4.0",
    "tsc-watch": "^4.6.0",
    "typescript": "4.4.3"
  }
}

内蔵SSD

SSDスペック

項目内容
機種IDMacBookAir10,1
チップApple M1
コアの総数8 (パフォーマンス: 4、効率性: 4)
メモリ8GB
SSD容量256GB ←こんな容量でDocker使うな
OSmacOS 11.6.1 (20G221)
カーネルDarwin 20.6.0

結果

# キャッシュ全削除
$ docker system prune -f
$ docker build . --platform=linux/amd64
[+] Building 384.9s (14/14) FINISHED                                                                                            
 => [internal] load build definition from Dockerfile                                                                       0.0s
 => => transferring dockerfile: 1.77kB                                                                                     0.0s
 => [internal] load .dockerignore                                                                                          0.0s
 => => transferring context: 2B                                                                                            0.0s
 => [internal] load metadata for docker.io/library/node:12-slim                                                            3.2s
 => [internal] load build context                                                                                          0.1s
 => => transferring context: 82.55kB                                                                                       0.0s
 => [deps 1/4] FROM docker.io/library/node:12-slim@sha256:d95c389b35126dcfdd9e61c9e33a69bebe930deaa24022753247a2e4568367f  7.0s
 => => resolve docker.io/library/node:12-slim@sha256:d95c389b35126dcfdd9e61c9e33a69bebe930deaa24022753247a2e4568367f2      0.0s
 => => sha256:d95c389b35126dcfdd9e61c9e33a69bebe930deaa24022753247a2e4568367f2 776B / 776B                                 0.0s
 => => sha256:98314046f193ab64149a76d4b2bc36e8a5e2f21fc430e46b30917b0feee8fbe4 1.37kB / 1.37kB                             0.0s
 => => sha256:196758114852cf89310964cb13d4d77119f6d31e45f2e7ee1d6bb11e406a5898 6.89kB / 6.89kB                             0.0s
 => => sha256:35b2232c987ef3e6249ed229afcca51cd83320e08f6700022f4a3644a11f00f2 22.53MB / 22.53MB                           4.2s
 => => sha256:7e6e186e178cd0422a6fbba09db8abffbd0fc35ff66daea061279e4ba7cae1d0 4.17kB / 4.17kB                             0.3s
 => => sha256:6acedcbd8b83b7350b1f261776c2c996219903ef793ad9c1daffb1bdc2caa3be 24.21MB / 24.21MB                           5.0s
 => => sha256:503a5a7bf5585c30ab772cdb153cd172a129caef81c958d398b4a99f4a37ed14 2.78MB / 2.78MB                             3.1s
 => => sha256:ea79b242907278cf31d803102522d2edb8ef6fa08f64bdf0e1aca73854d21738 464B / 464B                                 3.4s
 => => extracting sha256:35b2232c987ef3e6249ed229afcca51cd83320e08f6700022f4a3644a11f00f2                                  1.1s
 => => extracting sha256:7e6e186e178cd0422a6fbba09db8abffbd0fc35ff66daea061279e4ba7cae1d0                                  0.0s
 => => extracting sha256:6acedcbd8b83b7350b1f261776c2c996219903ef793ad9c1daffb1bdc2caa3be                                  1.1s
 => => extracting sha256:503a5a7bf5585c30ab772cdb153cd172a129caef81c958d398b4a99f4a37ed14                                  0.1s
 => => extracting sha256:ea79b242907278cf31d803102522d2edb8ef6fa08f64bdf0e1aca73854d21738                                  0.0s
 => [deps 2/4] WORKDIR /app                                                                                                0.1s
 => [runner 3/7] RUN apt-get update     && apt-get install -y ca-certificates libappindicator3-1 libxss1     libasound2  158.9s
 => [deps 3/4] COPY package.json yarn.lock ./                                                                              0.0s
 => [deps 4/4] RUN yarn install                                                                                           74.0s
 => [runner 4/7] RUN apt update     && apt-get install -y fonts-liberation fonts-noto-cjk       --no-install-recommends  172.7s
 => [runner 5/7] RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb                        7.9s
 => [runner 6/7] RUN dpkg --configure -a     && apt install -f     && dpkg -i ./google-chrome-stable_current_amd64.deb    30.1s
 => [runner 7/7] COPY --from=deps /app/node_modules ./node_modules                                                         1.7s
 => exporting to image                                                                                                     3.2s
 => => exporting layers                                                                                                    3.2s
 => => writing image sha256:4a4a5f1a07d5eb0c661ef612b0518ba6776b589c906bd737a57595d675145ea3                               0.0s

外付けSSDにおけるビルド時間

SSDスペック

SDSSDE81-1T00-GH25のApple M1における測定結果
項目内容
型番SDSSDE61-500G-G25
容量500 GB
インターフェイスUSB
設置タイプ外付け(ポータブル)
規格NVMe
カタログ上の読込速度1050 MB/s
カタログ上の書込速度1000 MB/s

参考: https://kakaku.com/item/K0001306911/spec/

結果

# キャッシュ全削除
$ docker system prune -f
$ docker build . --platform=linux/amd64
[+] Building 431.2s (14/14) FINISHED                                                                                                             
 => [internal] load build definition from Dockerfile                                                                                        0.2s
 => => transferring dockerfile: 1.77kB                                                                                                      0.0s
 => [internal] load .dockerignore                                                                                                           0.1s
 => => transferring context: 2B                                                                                                             0.0s
 => [internal] load metadata for docker.io/library/node:12-slim                                                                             3.3s
 => [deps 1/4] FROM docker.io/library/node:12-slim@sha256:d95c389b35126dcfdd9e61c9e33a69bebe930deaa24022753247a2e4568367f2                  8.0s
 => => resolve docker.io/library/node:12-slim@sha256:d95c389b35126dcfdd9e61c9e33a69bebe930deaa24022753247a2e4568367f2                       0.0s
 => => sha256:196758114852cf89310964cb13d4d77119f6d31e45f2e7ee1d6bb11e406a5898 6.89kB / 6.89kB                                              0.0s
 => => sha256:35b2232c987ef3e6249ed229afcca51cd83320e08f6700022f4a3644a11f00f2 22.53MB / 22.53MB                                            4.6s
 => => sha256:7e6e186e178cd0422a6fbba09db8abffbd0fc35ff66daea061279e4ba7cae1d0 4.17kB / 4.17kB                                              0.2s
 => => sha256:6acedcbd8b83b7350b1f261776c2c996219903ef793ad9c1daffb1bdc2caa3be 24.21MB / 24.21MB                                            4.0s
 => => sha256:d95c389b35126dcfdd9e61c9e33a69bebe930deaa24022753247a2e4568367f2 776B / 776B                                                  0.0s
 => => sha256:98314046f193ab64149a76d4b2bc36e8a5e2f21fc430e46b30917b0feee8fbe4 1.37kB / 1.37kB                                              0.0s
 => => sha256:503a5a7bf5585c30ab772cdb153cd172a129caef81c958d398b4a99f4a37ed14 2.78MB / 2.78MB                                              1.7s
 => => sha256:ea79b242907278cf31d803102522d2edb8ef6fa08f64bdf0e1aca73854d21738 464B / 464B                                                  1.9s
 => => extracting sha256:35b2232c987ef3e6249ed229afcca51cd83320e08f6700022f4a3644a11f00f2                                                   1.2s
 => => extracting sha256:7e6e186e178cd0422a6fbba09db8abffbd0fc35ff66daea061279e4ba7cae1d0                                                   0.0s
 => => extracting sha256:6acedcbd8b83b7350b1f261776c2c996219903ef793ad9c1daffb1bdc2caa3be                                                   1.3s
 => => extracting sha256:503a5a7bf5585c30ab772cdb153cd172a129caef81c958d398b4a99f4a37ed14                                                   0.1s
 => => extracting sha256:ea79b242907278cf31d803102522d2edb8ef6fa08f64bdf0e1aca73854d21738                                                   0.0s
 => [internal] load build context                                                                                                           0.0s
 => => transferring context: 82.55kB                                                                                                        0.0s
 => [deps 2/4] WORKDIR /app                                                                                                                 0.2s
 => [runner 3/7] RUN apt-get update     && apt-get install -y ca-certificates libappindicator3-1 libxss1     libasound2 libatk-bridge2.0  194.8s
 => [deps 3/4] COPY package.json yarn.lock ./                                                                                               0.0s
 => [deps 4/4] RUN yarn install                                                                                                           106.9s
 => [runner 4/7] RUN apt update     && apt-get install -y fonts-liberation fonts-noto-cjk       --no-install-recommends                   179.4s
 => [runner 5/7] RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb                                         8.4s
 => [runner 6/7] RUN dpkg --configure -a     && apt install -f     && dpkg -i ./google-chrome-stable_current_amd64.deb                     30.9s
 => [runner 7/7] COPY --from=deps /app/node_modules ./node_modules                                                                          2.1s
 => exporting to image                                                                                                                      3.9s
 => => exporting layers                                                                                                                     3.9s
 => => writing image sha256:e1dc3fe366d42f9df409eae77e227cbc43bfcb536f5c83b4d2f5dd6a0a785374                                                0.0s

結論

差46.3秒。ほとんどが大量のライブラリをインストールする部分だ。

ダウンロード時間を考慮すると、決定的な違いはないと思って良さそうだ。

Tweet

コメント

記事の内容が最新のものと異なる場合があります。ご了承ください。

コメントを残す

メールアドレスが公開されることはありません。