はじめに
ラズパイでDockerfileをbuildする際にうまくいかなかった事例がありました。
ラズパイだと以下のように普通にpostgresql-server-dev-17を入れようとすると以下のようなエラーになってしまいます。
> [3/4] RUN apt-get install -y postgresql-server-dev-17:
6.913 The following packages have unmet dependencies:
6.913 libpq-dev : Depends: libpq5 (= 17.6-0+deb13u1) but 17.6-2.pgdg13+1 is to be installed
6.926 E: Unable to correct problems, you have held broken packages.
6.927 E: The following information from --solver 3.0 may provide additional context:
6.927 Unable to satisfy dependencies. Reached two conflicting decisions:
6.927 1. libpq5:armhf=17.6-0+deb13u1 is not selected for install
6.927 2. libpq5:armhf=17.6-0+deb13u1 is selected as a downgrade because:
6.927 1. postgresql-server-dev-17:armhf=17.6-0+deb13u1 is selected for install
6.927 2. postgresql-server-dev-17:armhf Depends libpq-dev (>= 17~~)
6.928 3. libpq-dev:armhf Depends libpq5 (= 17.6-0+deb13u1)これは、
libpq-dev パッケージは libpq5 バージョン 17.6-0+deb13u1 に依存している
しかし現在インストールされようとしている libpq5 は 17.6-2.pgdg13+1
よって、バージョンが一致せず依存関係が解決できなく、インストールが失敗しているようです。
今回はこちらを解消します。
解消
docker buildをラズパイ内で試していた際は、以下をRUNでDockerfileに追加すれば解消しました。
apt install libpq5=17.6-0+deb13u1しかし、CICDの時は以下のようなエラーが出たので、
Error: Packages were downgraded and -y was used without --allow-downgrades.「–allow-downgrades」を付ける必要がありました。
最終的に、Dockerfileは以下のようになりました。
FROM postgres:17
RUN apt-get update && apt-get upgrade && \
apt-get install -y git make gcc
RUN apt install -y --allow-downgrades libpq5=17.6-0+deb13u1
RUN apt-get install -y postgresql-server-dev-all
RUN cd /tmp && \
git clone --branch v0.5.1 https://github.com/pgvector/pgvector.git && \
cd pgvector && \
make && \
make install && \
cd ../ && rm -rf pgvector最後に
ラズパイはARMという32ビットアーキテクチャーであり、僕がアプリケーションの検証環境として普段使っているPCはAMD64という64ビットアーキテクチャーなのでその違いによる影響はでてきたりします。
ここは難しいところですね。
とりあえず、暫定対応として、検証環境用のDockerfileと本番環境用のDockerfileを別々に作成して対応しています。
