13
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?

はじめに

Webサービスでパスワード認証に bcrypt を使っている人向けの話です。

既存のNode.jsアプリを Docker環境へ移行した際に、
bcryptSegmentation Fault(seg fault)で落ちる問題に遭遇しました。

結論から言うと、
原因は alpine-node イメージを使っていたことでした。

Docker化にそこそこ時間を取られたので、同じ罠にハマる人を減らすために記録として残します。


発生した問題

Docker上でアプリを起動すると、以下のような挙動になります。

  • ローカル環境では正常に動作
  • Docker環境では bcrypt 実行時に seg fault
  • エラーログがほとんど残らず、突然プロセスが落ちる
Segmentation fault
import bcrypt from "bcrypt";

await bcrypt.compare(password, hash); // ← ここで落ちる

原因:alpine-node と libc の問題

Dockerイメージに node:alpine(Alpine Linux) を使っていました。

  • Alpine Linux は musl libc
  • bcrypt はネイティブアドオン(C/C++)依存
  • 必要なライブラリ不足・互換性問題で seg fault 発生

解決策:Debian ベースの Node イメージを使う

修正前(問題あり)

FROM node:18-alpine

修正後(解決)

FROM node:18-bullseye
# or
FROM node:18-bookworm

これだけで安定しました。


まとめ

  • bcrypt + Docker で seg fault → Alpine を疑う
  • 安定性重視なら Debian ベースが無難
  • 軽量より「確実に動く」を優先すべき

Docker移行で詰まった人の助けになれば幸いです。

13
0
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
13
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?