実現したいこと
docker compose buildでイメージを保存したい。
前提
windows11上にdocker desktop ver.4.25.2をインストールしています。
エディタはVSCodeで、ターミナルから各種コマンドを実行しています。
docker composeでruby3.2.2とrails、mySQL8.xでwebとdbサービスを実行してイメージ化しようとしています。
発生している問題・エラーメッセージ
docker compose run web rails new . --force --database=mysql
はエラー無く実行完了できたが、
その後、docker compose buildを実行すると
以下の様に途中で強制的に停止してしまう。
> docker compose --verbose build --no-cache time="2023-12-17T20:33:09+09:00" level=debug msg="using default config store \"C:\\\\Users\\\\haya-\\\\.docker\\\\buildx\"" [+] Building 1.9s (6/9) docker:default => [web internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [web internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 515B 0.0s => [web internal] load metadata for docker.io/library/ruby:3.2 1.5s => CACHED [web 1/5] FROM docker.io/library/ruby:3.2@sha256:e3f503db7f451e6fd48221ecafbf1046 0.0s => CANCELED [web internal] load build context 0.1s => => transferring context: 2.40MB 0.1s => CANCELED [web 2/5] RUN curl -fsSL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearm 0.3s time="2023-12-17T20:33:09+09:00" level=debug msg="using default config store \"C:\\\\Users\\\\haya-\\\\.docker\\\\buildx\"" time="2023-12-17T20:33:09+09:00" level=debug msg="serving grpc connection" time="2023-12-17T20:33:09+09:00" level=debug msg="stopping session" span="load buildkit capabilities" time="2023-12-17T20:33:10+09:00" level=debug msg="serving grpc connection" time="2023-12-17T20:33:11+09:00" level=debug msg="stopping session" failed to solve: Canceled: context canceled
該当のソースコード
フォルダ構成は以下
App
├src
│└Gemfile
├compose.yml
└Dockerfile
Gemfile
1source "https://rubygems.org" 2 3git_source(:github) { |repo_name|"https://github.com/#{repo_name}" } 4 5gem "rails"
Dockerfile
1FROM ruby:3.2 2 3RUN curl -fsSL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor -o /usr/share/keyrings/yarnpubkey.gpg \ 4 && echo "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/yarnpubkey.gpg] https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \ 5 && apt update && apt install -y yarn nodejs 6 7WORKDIR /app 8COPY ./src /app 9 10RUN bundle config --local set path 'vendor/bundle' \ 11 && bundle install
compose.yml
1services: 2 db: 3 image: mysql:latest 4 command: --default-authentication-plugin=caching_sha2_password 5 volumes: 6 - ./src/db/mysql_data:/var/lib/mysql 7 environment: 8 MYSQL_ROOT_PASSWORD: password 9 web: 10 build: . 11 command: bundle exec rails s -p 3000 -b '0.0.0.0' 12 volumes: 13 - ./src:/app 14 ports: 15 - "3000:3000" 16 depends_on: 17 - db
試したこと
①動作しているコンテナの確認
> docker compose ps NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS rails_docker2-db-1 mysql:latest "docker-entrypoint.s…" db 11 minutes ago Up 11 minutes 3306/tcp, 33060/tcp
②web用のコンテナを一時的に立ち上げてDockerfileの各コマンドを実行してみた。
> docker compose run --rm web /bin/bash [+] Building 0.0s (0/0) docker:default [+] Creating 1/0 ✔ Container rails_docker2-db-1 Created 0.0s [+] Running 1/1 ✔ Container rails_docker2-db-1 Started 0.3s [+] Building 0.0s (0/0) docker:default root@b74cd8667f8a:/app# curl -fsSL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor -o /etc/apt/keyrings/yarnpubkey.gpg File '/etc/apt/keyrings/yarnpubkey.gpg' exists. Overwrite? (y/N) y root@b74cd8667f8a:/app# echo "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/yarnpubkey.gpg] https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list deb [arch=amd64 signed-by=/etc/apt/keyrings/yarnpubkey.gpg] https://dl.yarnpkg.com/debian/ stable main root@b74cd8667f8a:/app# apt update Hit:1 http://deb.debian.org/debian bookworm InRelease Hit:2 https://dl.yarnpkg.com/debian stable InRelease Hit:3 http://deb.debian.org/debian bookworm-updates InRelease Hit:4 http://deb.debian.org/debian-security bookworm-security InRelease Reading package lists... Done Building dependency tree... Done Reading state information... Done 15 packages can be upgraded. Run 'apt list --upgradable' to see them. root@b74cd8667f8a:/app# apt install -y yarn nodejs Reading package lists... Done Building dependency tree... Done Reading state information... Done yarn is already the newest version (1.22.19-1). nodejs is already the newest version (18.13.0+dfsg1-1). 0 upgraded, 0 newly installed, 0 to remove and 15 not upgraded. root@b74cd8667f8a:/app# bundle config --local set path 'vendor/bundle' root@b74cd8667f8a:/app# bundle install Fetching gem metadata from https://rubygems.org/......... Using rake 13.1.0 (略) Bundle complete! 14 Gemfile dependencies, 82 gems now installed. Use `bundle info [gemname]` to see where a bundled gem is installed. Post-install message from rubyzip: RubyZip 3.0 is coming!
③以下で止まっていそうで、yarnpubkey.gpgをrun時に作成したためにbuild時にファイルが存在するので停止しているような気がしますが、ボールドテキスト何を試せばよいかよくわからないです。
gpg --dearmor -o /etc/apt/keyrings/yarnpubkey.gpg
補足情報(FW/ツールのバージョンなど)
Gemfile.lock
1GEM 2 remote: https://rubygems.org/ 3(略) 4 public_suffix (5.0.4) 5 puma (6.4.0) 6 nio4r (~> 2.0) 7 racc (1.7.3) 8 rack (3.0.8) 9 rack-session (2.0.0) 10 rack (>= 3.0.0) 11 rack-test (2.1.0) 12 rack (>= 1.3) 13 rackup (2.1.0) 14 rack (>= 3) 15 webrick (~> 1.8) 16 rails (7.1.2) 17 actioncable (= 7.1.2) 18 actionmailbox (= 7.1.2) 19 actionmailer (= 7.1.2) 20 actionpack (= 7.1.2) 21 actiontext (= 7.1.2) 22 actionview (= 7.1.2) 23 activejob (= 7.1.2) 24 activemodel (= 7.1.2) 25 activerecord (= 7.1.2) 26 activestorage (= 7.1.2) 27 activesupport (= 7.1.2) 28 bundler (>= 1.15.0) 29 railties (= 7.1.2) 30 rails-dom-testing (2.2.0) 31 activesupport (>= 5.0.0) 32 minitest 33 nokogiri (>= 1.6) 34 rails-html-sanitizer (1.6.0) 35 loofah (~> 2.21) 36 nokogiri (~> 1.14) 37 railties (7.1.2) 38 actionpack (= 7.1.2) 39 activesupport (= 7.1.2) 40 irb 41 rackup (>= 1.0.0) 42 rake (>= 12.2) 43 thor (~> 1.0, >= 1.2.2) 44 zeitwerk (~> 2.6) 45 rake (13.1.0) 46 rdoc (6.6.2) 47 psych (>= 4.0.0) 48 regexp_parser (2.8.3) 49 reline (0.4.1) 50 io-console (~> 0.5) 51 rexml (3.2.6) 52 ruby2_keywords (0.0.5) 53 rubyzip (2.3.2) 54 selenium-webdriver (4.16.0) 55 rexml (~> 3.2, >= 3.2.5) 56 rubyzip (>= 1.2.2, < 3.0) 57 websocket (~> 1.0) 58 sprockets (4.2.1) 59 concurrent-ruby (~> 1.0) 60 rack (>= 2.2.4, < 4) 61 sprockets-rails (3.4.2) 62 actionpack (>= 5.2) 63 activesupport (>= 5.2) 64 sprockets (>= 3.0.0) 65 stimulus-rails (1.3.0) 66 railties (>= 6.0.0) 67 stringio (3.1.0) 68 thor (1.3.0) 69 timeout (0.4.1) 70 turbo-rails (1.5.0) 71 actionpack (>= 6.0.0) 72 activejob (>= 6.0.0) 73 railties (>= 6.0.0) 74 tzinfo (2.0.6) 75 concurrent-ruby (~> 1.0) 76 web-console (4.2.1) 77 actionview (>= 6.0.0) 78 activemodel (>= 6.0.0) 79 bindex (>= 0.4.0) 80 railties (>= 6.0.0) 81 webrick (1.8.1) 82 websocket (1.2.10) 83 websocket-driver (0.7.6) 84 websocket-extensions (>= 0.1.0) 85 websocket-extensions (0.1.5) 86 xpath (3.2.0) 87 nokogiri (~> 1.8) 88 zeitwerk (2.6.12) 89 90PLATFORMS 91 x86_64-linux 92 93DEPENDENCIES 94 bootsnap 95 capybara 96 debug 97 importmap-rails 98 jbuilder 99 mysql2 (~> 0.5) 100 puma (>= 5.0) 101 rails (~> 7.1.2) 102 selenium-webdriver 103 sprockets-rails 104 stimulus-rails 105 turbo-rails 106 tzinfo-data 107 web-console 108 109RUBY VERSION 110 ruby 3.2.2p53 111 112BUNDLED WITH 113 2.4.10
あなたの回答
tips
プレビュー