2
0

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 1 year has passed since last update.

Dockerfileのベースイメージタグは OS名まで書いた方が安全

2
Last updated at Posted at 2023-06-14

背景

  • AWS ECS内で Node.js v18 イメージを使ってマルチステージビルドしていた時の話
  • 執筆時点(2023年6月14日)の2日前くらいから急にCodeBuildでエラーが出るようになった

ディレクトリ構成

app/以下にNext.jsのプロジェクトがあるものとする

当たった問題

FROM node:18 AS builder

ENV NODE_ENV=development

WORKDIR /app
COPY app/package.json ./
COPY app/package-lock.json ./
COPY app/.npmrc ./
RUN npm ci --ignore-scripts 
COPY ./app .
RUN npm run build

FROM node:18-bullseye-slim AS runner
ENV NODE_ENV=production

WORKDIR /app
COPY --frombuilder /app ./app
RUN npm ci --ignore-scripts

COPY --from=builder /admin/next.config.js ./
COPY --from=builder /admin/.next ./.next
COPY --from=builder /admin/public ./public

CMD ["npm", "run" ,"start"]

としていたらNode:18の最初の

RUN npm ci --ignore-scripts 

にてエラーが出ていた

...

#10 [builder 3/9] RUN npm install
#10       digest: sha256:fe6d1ed129e1d452011555e9d8762518d3b697ae55d830ac079ecc89bb05e25c
#10         name: "[builder 3/9] RUN npm install"
#10      started: 2023-06-14 11:07:30.816373024 +0000 UTC
#10 0.270 node[8]: ../src/node_platform.cc:68:std::unique_ptr<long unsigned int> node::WorkerThreadsTaskRunner::DelayedTaskScheduler::Start(): Assertion `(0) == (uv_thread_create(t.get(), start_thread, this))' failed.
#10 0.270  1: 0xb7a940 node::Abort() [node]
#10 0.271  2: 0xb7a9be  [node]
#10 0.271  3: 0xbe98be  [node]
#10 0.272  4: 0xbe99a1 node::NodePlatform::NodePlatform(int, v8::TracingController*, v8::PageAllocator*) [node]
#10 0.272  5: 0xb38f5b node::InitializeOncePerProcess(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, node::ProcessFlags::Flags) [node]
#10 0.273  6: 0xb395ab node::Start(int, char**) [node]
#10 0.273  7: 0x7fd516a4918a  [/lib/x86_64-linux-gnu/libc.so.6]
#10 0.273  8: 0x7fd516a49245 __libc_start_main [/lib/x86_64-linux-gnu/libc.so.6]
#10 0.273  9: 0xabbdee _start [node]
#10 0.276 Aborted (core dumped)
#10    completed: 2023-06-14 11:07:31.182967785 +0000 UTC
#10     duration: 366.594761ms
#10        error: "executor failed running [/bin/sh -c npm install]: exit code: 134"

executor failed running [/bin/sh -c npm install]: exit code: 134

...

原因

DockerHubを見に行くと、ベースイメージとして使っていたNode:18のベースOSが Debian12(Bookworm)に変更されていた。

念の為、Node.jsの公式イメージも見に行ったが、記事執筆時点で3日前に Debian12 Bookwormベースのものが公開されていた。
https://github.com/nodejs/docker-node/commits/main/18/bookworm

解決方法

builder のDockerfileのベースイメージのタグはOSを明示的に指定する

FROM node:18-bullseye AS builder

結果

無事デプロイできました🎉

2
0
1

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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?