Dockerコンテナ内からホスト側にアクセスする方法

Dockerで立てたコンテナ内から別コンテナに接続したかったのですが、ネットワークが別になるのでコンテナ名では繋げられず困っていました。

例えばコンテナAでDBを立ち上げていて、コンテナBからDBに接続したいなど。

考えを変えて、ホスト側にさえアクセスできれば勝手にルーティングされると思い、Dockerコンテナ内からホスト側にアクセスする方法を探したところ

host.docker.internal

でホスト側にアクセスできるよう。

なのでコンテナB側の接続情報を host.docker.internal:3306 とすることでアクセスができました。


こちらの記事を参考にしました。

uepon.hatenadiary.com

Sidekiqを6.4.0に上げるとsidekiq-historyでundefined method `new' for Sidekiq::Worker:Module

環境

  • ruby 3.0.3
  • rails 6.1.4.4
  • sidekiq 6.4.0
  • sidekiq-history 0.0.11

以下のエラー

NoMethodErrorvendor/bundle/ruby/3.0.0/gems/sidekiq-history-0.0.11/lib/sidekiq/history/middleware.rb:14
undefined method `new' for Sidekiq::Worker:Module

sidekiq-history のバージョンが古いのが原因でした。 こちらのコミットで sidekiq 6.2.2 以上に対応していたので sidekiq-history をアップデートします。

github.com

bundle update sidekiq-history

バージョンが上がったのを確認

$ git diff

-    sidekiq-history (0.0.11)
+    sidekiq-history (0.0.12)

gemのアップデートをしたら libffi.so.8: cannot open shared object file: No such file or directory でrailsが動かなくなった

libffi.so.8 が無いと怒られた

/home/usernam/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require': libffi.so.8: cannot open shared object file: No such file or directory - /home/akinov/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/ffi-1.15.4/lib/ffi_c.so (LoadError)

環境

やったこと

libffi.so.8libffi8ubuntu1 をインストールしたいので以下の記事を参照

askubuntu.com

gdebi が無いのでまずインストール

$ sudo apt install gdebi

/usr/lib/apt/methods/http: error while loading shared libraries: libffi.so.7: cannot open shared object file: No such file or directory
E: Method http has died unexpectedly!
E: Sub-process http returned an error code (127)
E: Method /usr/lib/apt/methods/http did not start correctly
E: Method http has died unexpectedly!

そもそも libffi.so.7 も無いと怒られたのでシンボリックリンクを張る

$ find /usr/lib -name "libffi.so.*"
/usr/lib/x86_64-linux-gnu/libffi.so.7.1.0

$ cd /usr/lib/x86_64-linux-gnu
$ sudo ln -s libffi.so.7.1.0 libffi.so.7

gdebi インストールし直し

$ sudo apt-get install gdebi

Get:92 http://archive.ubuntu.com/ubuntu focal/main amd64 t1utils amd64 1.41-3 [56.1 kB]
Err:93 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 lintian all 2.62.0ubuntu1
  404  Not Found [IP: 91.189.88.152 80]
Fetched 16.5 MB in 6s (2776 kB/s)
E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/l/lintian/lintian_2.62.0ubuntu1_all.deb  404  Not Found [IP: 91.189.88.152 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

途中まで上手くいくがパッケージが見つからない
他記事で apt-get のアプデとあったので実行

github.com

$ sudo apt-get update
$ sudo apt-get install gdebi
=> 成功

libffi8_3.4.2-1ubuntu5_amd64.deb をダウンロードして実行

$ wget http://kr.archive.ubuntu.com/ubuntu/pool/main/libf/libffi/libffi8_3.4.2-1ubuntu5_amd64.deb

$ sudo gdebi libffi8_3.4.2-1ubuntu5_amd64.deb
Reading package lists... Done
Building dependency tree
Reading state information... Done
Traceback (most recent call last):
  File "/usr/bin/gdebi", line 86, in <module>
    if not debi.open(args[0]):
  File "/usr/share/gdebi/GDebi/GDebiCli.py", line 73, in open
    self._deb = DebPackage(file, self._cache)
  File "/usr/share/gdebi/GDebi/DebPackage.py", line 31, in __init__
    super(DebPackage, self).__init__(cache=cache, filename=filename)
  File "/usr/lib/python3/dist-packages/apt/debfile.py", line 77, in __init__
    self.open(filename)
  File "/usr/lib/python3/dist-packages/apt/debfile.py", line 88, in open
    control = self._debfile.control.extractdata("control")
LookupError: There is no member named 'control'

LookupError: There is no member named 'control' と怒られる

github.com

内部の圧縮されたファイルの拡張子を確認して、対応する解凍アプリをインストールしろとのこと
確認すると zst と出てきたので zstd をインストール

$ sudo apt-get install zstd
=> 成功
$ sudo gdebi libffi8_3.4.2-1ubuntu5_amd64.deb
=> 成功

インストールされていることを確認

$ la /usr/lib/x86_64-linux-gnu | grep libffi
-rw-r--r--  1 root root  62K Mar 24  2020 libffi.a
lrwxrwxrwx  1 root root   15 Mar 24  2020 libffi.so -> libffi.so.7.1.0
lrwxrwxrwx  1 root root   15 Jan  5 11:28 libffi.so.7 -> libffi.so.7.1.0
-rw-r--r--  1 root root  43K Mar 24  2020 libffi.so.7.1.0
lrwxrwxrwx  1 root root   15 Sep 16 01:03 libffi.so.8 -> libffi.so.8.1.0
-rw-r--r--  1 root root  43K Sep 16 01:03 libffi.so.8.1.0
-rw-r--r--  1 root root  62K Mar 24  2020 libffi_pic.a