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

Docker環境構築時はnode_modulesを.dockerignoreに追加する

Posted at

概要

Dockerでnode.jsのコンテナを使用してdocker-compose up --buildするとき、下記エラーに苦戦したため解決策をメモします。

time="2025-01-14T08:58:14+09:00" level=warning msg="The \"DISPLAY\" variable is not set. Defaulting to a blank string."
[+] Building 13.4s (5/9)                                                                                    docker:desktop-linux
 => [frontend internal] load build definition from Dockerfile                                                               0.0s
 => => transferring dockerfile: 583B                                                                                        0.0s
 => [frontend internal] load metadata for docker.io/library/node:22                                                         2.1s
 => [frontend internal] load .dockerignore                                                                                  0.0s
 => => transferring context: 196B                                                                                           0.0s
 => [frontend 1/5] FROM docker.io/library/node:22@sha256:99981c3d1aac0d98cd9f03f74b92dddf30f30ffb0b34e6df8bd96283f62f12c6   0.0s
 => => resolve docker.io/library/node:22@sha256:99981c3d1aac0d98cd9f03f74b92dddf30f30ffb0b34e6df8bd96283f62f12c6            0.0s
 => ERROR [frontend internal] load build context                                                                           11.1s 
 => => transferring context: 234.64MB                                                                                      11.1s 
------
 > [frontend internal] load build context:
------
failed to solve: archive/tar: unknown file mode ?rwxr-xr-x

解決策

コンテナへコピーするディレクト直下に下記ファイルを作成して、Windowsなどのホストマシンからコンテナへnode_modulesフォルダをコピーされないようにします。

.dockerignore
sample_remix_react/node_modules

余談

Windows環境のOneDrive内でプロジェクトを管理していると、本エラーが発生するようです。私の場合はOneDriveに保存すること維持したいため、.dockerignoreを作成することで対応しました。
https://github.com/docker/for-win/issues/14083#issuecomment-2528022302

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