2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Docker】「E: Package 'mysql-client' has no installation candidate」のエラー解決方法

Posted at

概要

最小限のDockerイメージを作成していたらE: Package 'mysql-client' has no installation candidateというエラーになりました。

エラー原因

利用したDockerfileは以下。簡単なRDSクエリを実行するだけのDockerイメージです。

# 使用するベースイメージを選択
FROM python:3.6

# 必要なパッケージをインストール
RUN apt-get update && apt-get install -y \
    mysql-client \
    && rm -rf /var/lib/apt/lists/*

# イメージを起動したときに実行されるコマンド
CMD ["/bin/bash"]

これで生じたエラー全文が以下です。

[+] Building 5.7s (5/5) FINISHED
 => [internal] load build definition from Dockerfile                                                          0.0s
 => => transferring dockerfile: 336B                                                                          0.0s
 => [internal] load .dockerignore                                                                             0.0s
 => => transferring context: 2B                                                                               0.0s
 => [internal] load metadata for docker.io/library/python:3.6                                                 0.0s
 => CACHED [1/2] FROM docker.io/library/python:3.6                                                            0.0s
 => ERROR [2/2] RUN apt-get update && apt-get install -y     mysql-client     && rm -rf /var/lib/apt/lists/*  5.6s
------
 > [2/2] RUN apt-get update && apt-get install -y     mysql-client     && rm -rf /var/lib/apt/lists/*:
#5 0.468 Get:1 http://security.debian.org/debian-security bullseye-security InRelease [48.4 kB]
#5 0.508 Get:2 http://deb.debian.org/debian bullseye InRelease [116 kB]
#5 0.650 Get:3 http://security.debian.org/debian-security bullseye-security/main arm64 Packages [242 kB]
#5 0.827 Get:4 http://deb.debian.org/debian bullseye-updates InRelease [44.1 kB]
#5 0.848 Get:5 http://deb.debian.org/debian bullseye/main arm64 Packages [8071 kB]
#5 4.217 Get:6 http://deb.debian.org/debian bullseye-updates/main arm64 Packages [14.9 kB]
#5 4.841 Fetched 8536 kB in 4s (1898 kB/s)
#5 4.841 Reading package lists...
#5 5.154 Reading package lists...
#5 5.421 Building dependency tree...
#5 5.488 Reading state information...
#5 5.499 Package mysql-client is not available, but is referred to by another package.
#5 5.499 This may mean that the package is missing, has been obsoleted, or
#5 5.499 is only available from another source
#5 5.499
#5 5.539 E: Package 'mysql-client' has no installation candidate
------
executor failed running [/bin/sh -c apt-get update && apt-get install -y     mysql-client     && rm -rf /var/lib/apt/lists/*]: exit code: 100

このエラーメッセージは、DockerイメージのビルドプロセスでMySQLクライアントのパッケージをインストールしようとしたときに、mysql-clientパッケージが見つからなかった、と言っていますね。

解決方法

DebianベースのDockerイメージを使用している場合、mysql-clientパッケージの名前が異なることがあるとのこと。

Debian系のLinuxディストリビューションでは、MySQLクライアントはmysql-clientではなくdefault-mysql-clientなどの名前で提供されるよう。

以下のように修正したら、無事にイメージが作成できました。

Copy code
# 使用するベースイメージを選択
FROM python:3.6

# 必要なパッケージをインストール
RUN apt-get update && apt-get install -y default-mysql-client && rm -rf /var/lib/apt/lists/*

# イメージを起動したときに実行されるコマンド
CMD ["/bin/bash"]
2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?