実現したいこと
docker compose を使って、dbコンテナと apiコンテナ(ruby on rails)を起動させたいです。
発生している問題・分からないこと
Dockerfile内の、COPYの部分でエラーが起き、コンテナにローカルファイルをコピーできません。docker側が、ローカルファイルを見つけられていないようです。
エラーメッセージ
error
1~/Study/Portfolio/docker_tryal1 2❯ docker compose up -d 3 4[+] Running 12/12 5 ✔ db Pulled 12.7s 6 ✔ c6a0976a2dbe Pull complete 2.1s 7 ✔ 8dd4f8e415ca Pull complete 0.8s 8 ✔ 6e01a6ece3af Pull complete 0.9s 9 ✔ 6cfdeffd9140 Pull complete 2.7s 10 ✔ 73fed55ee93c Pull complete 1.6s 11 ✔ 39c3b4c317a6 Pull complete 2.3s 12 ✔ de375e24a2a7 Pull complete 4.1s 13 ✔ d5ad96b86b99 Pull complete 3.1s 14 ✔ 5241e2cffaa1 Pull complete 5.7s 15 ✔ 4e39d469d2ab Pull complete 4.2s 16 ✔ f718345410af Pull complete 4.9s 17[+] Building 1.6s (12/13) docker:desktop-linux 18 => [api internal] load build definition from Dockerfile 0.0s 19 => => transferring dockerfile: 340B 0.0s 20 => [api internal] load metadata for docker.io/library/ruby:3.3.1 1.5s 21 => [api internal] load .dockerignore 0.0s 22 => => transferring context: 2B 0.0s 23 => [api 1/9] FROM docker.io/library/ruby:3.3.1@sha256:ce23a408a008a39960c168117f0dd297674e8f6fddd121efc7775f0a75974eb6 0.0s 24 => [api internal] load build context 0.0s 25 => => transferring context: 2.73kB 0.0s 26 => CACHED [api 2/9] RUN mkdir /api 0.0s 27 => CACHED [api 3/9] WORKDIR /api 0.0s 28 => ERROR [api 4/9] COPY Gemfile /api/Gemfile 0.0s 29 => ERROR [api 5/9] COPY Gemfile.lock /api/Gemfile.lock 0.0s 30 => CACHED [api 6/9] RUN bundle install 0.0s 31 => CACHED [api 7/9] COPY . /api 0.0s 32 => ERROR [api 8/9] COPY entrypoint.sh /usr/bin/ 0.0s 33------ 34 > [api 4/9] COPY Gemfile /api/Gemfile: 35------ 36------ 37 > [api 5/9] COPY Gemfile.lock /api/Gemfile.lock: 38------ 39------ 40 > [api 8/9] COPY entrypoint.sh /usr/bin/: 41------ 42failed to solve: failed to compute cache key: failed to calculate checksum of ref 62db5faa-2e83-4f28-bde6-542c2a0bec15::zwpd25ocw5u2pxvnamfaysevo: "/entrypoint.sh": not found 43
該当のソースコード
docker
1services: 2 db: 3 image: mysql:8.0.36 4 environment: 5 MYSQL_ROOT_PASSWORD: password 6 volumes: 7 - sample-db:/var/lib/mysql 8 ports: 9 - "3306:3306" 10 11 api: 12 build: 13 context: . 14 dockerfile: ./backend/Dockerfile 15 command: /bin/bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0' " 16 volumes: 17 - ./backend:/api 18 environment: 19 TZ: Asia/Tokyo 20 RAILS_ENV: development 21 depends_on: 22 - db 23 ports: 24 - 3001:3000 25 26volumes: 27 sample-db: 28
Dockerfile
1FROM ruby:3.3.1 2 3RUN mkdir /api 4WORKDIR /api 5 6COPY Gemfile /api/Gemfile 7COPY Gemfile.lock /api/Gemfile.lock 8 9RUN bundle install 10 11COPY . /api 12 13COPY entrypoint.sh /usr/bin/ 14RUN chmod +x /usr/bin/entrypoint.sh 15 16ENTRYPOINT ["/usr/bin/entrypoint.sh"] 17 18EXPOSE 3000 19 20CMD ["rails", "server", "-b", "0.0.0.0"] 21
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他
上記の詳細・結果
ディレクトリ構造は以下の通りです。
docker_tryal1
├── backend
│ ├── Gemfile
│ ├── Gemfile.lock
│ ├── entrypoint.sh
│ └── Dockerfile
├── frontend
└── docker-compose.yml
調べると、ほとんどが①ファイルパスの問題や 、② .dockerignore によるもののようですが、
① Dockerfileと同一階層であるため、上位階層を参照する際に起こるエラーではないようです。COPY ./Gemfile /api/Gemfile のような表記も試しましたが、変化ありませんでした。
② .dockerignore ファイルは、そもそも作っていません。
補足
バージョンは以下の通りです。
❯ docker compose version
Docker Compose version v2.26.1-desktop.1
❯ docker version
Client:
Cloud integration: v1.0.35+desktop.13
Version: 26.0.0
API version: 1.45
Go version: go1.21.8
Built: Wed Mar 20 15:14:46 2024
OS/Arch: darwin/arm64
Context: desktop-linux
Server: Docker Desktop 4.29.0 (145265)
Engine:
Version: 26.0.0
API version: 1.45 (minimum version 1.24)
Go version: go1.21.8
Built: Wed Mar 20 15:18:02 2024
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: 1.6.28
runc:
Version: 1.1.12
docker-init:
Version: 0.19.0

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2024/05/13 01:10