1
1

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でパッケージがインストールできない

Posted at

概要

  • タイムゾーンのパッケージをインストールするためにRUN apk add --no-cache tzdataをDockerfileに記載して実行したが、エラーがでてインストールできなかった。解決方法を簡単にまとめる。

詳細

  • Dockerイメージ

    • mailhog/mailhog:v1.0.1
  • エラー内容

     > [mailhog 2/3] RUN apk add --no-cache tzdata:
    #0 0.208 ERROR: Unable to lock database: Permission denied
    #0 0.208 ERROR: Failed to open apk database: Permission denied
    

原因

  • コマンド実行ユーザーの権限不足らしい。
  • 基本Dockerfileのコマンドはrootユーザーが実行する用になっているが、セキュリティ的観点からroot以外のユーザーでコマンドを実行しているDockerイメージがあるらしい。
  • apkコマンドを実行する前にrootユーザーに切り替えてあげればいいらしい。

方法

  • 下記のように記載されたDockerfileを使ってコンテナを作る。

    FROM mailhog/mailhog:v1.0.1
    
    USER root
    # タイムゾーンのパッケージをインストール
    RUN apk add --no-cache tzdata
    
    ENV TZ Asia/Tokyo
    RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
    
    USER mailhog
    
1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?