LoginSignup
7
4

More than 3 years have passed since last update.

【Tips】UbuntuへのDockerインストール時に誤ったリポジトリを追加してしまった場合の対処方法

Last updated at Posted at 2019-11-14

概要

UbuntuにDockerをインストールする際に、x86系のCPU入りPCなのに誤ってARM用のリポジトリを設定してしまった場合の修正方法。このミスをすると手順の最後にあたるsudo apt install docker-ceの段でパッケージが見つからないとしてインストールが失敗する。

誤った入力(手続き全体のうち add-apt-repository 部分のみ)

sudo add-apt-repository "deb [arch=armhf] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

正しい入力(同上)

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

sudo apt install docker-ceのエラーメッセージ

パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています                
状態情報を読み取っています... 完了
パッケージ docker-ce は使用できませんが、別のパッケージから参照されます。
これは、パッケージが欠落しているか、廃止されたか、または別のソース
からのみ利用可能であることを意味します。
しかし、以下のパッケージが置き換えます:
  docker-ce-cli:armhf

E: パッケージ 'docker-ce' にはインストール候補がありません

環境

  • Ubuntu 16.04.6 LTS (Xenial Xerus)
    • 18.04 LTS に関しては補足参照(基本的にこの記事で書かれている内容と同じ)

解決方法

add-apt-repository のやり直し

add-apt-repository部分以外は問題がないので、上記の「正しい入力」で示されているadd-apt-repositoryを行えば問題ない。以下再掲。

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

誤って追加されたリポジトリの削除

誤ったリポジトリと正しいリポジトリが両方追加されたままの状態で

sudo apt update

とすると、以下の警告がででしまう。

W: ターゲット Packages (stable/binary-all/Packages) は /etc/apt/sources.list:54 と /etc/apt/sources.list:57 で複数回設定されています
W: ターゲット Translations (stable/i18n/Translation-ja_JP) は /etc/apt/sources.list:54 と /etc/apt/sources.list:57 で複数回設定されています
W: ターゲット Translations (stable/i18n/Translation-ja) は /etc/apt/sources.list:54 と /etc/apt/sources.list:57 で複数回設定されています
W: ターゲット Translations (stable/i18n/Translation-en) は /etc/apt/sources.list:54 と /etc/apt/sources.list:57 で複数回設定されています
W: ターゲット DEP-11 (stable/dep11/Components-amd64.yml) は /etc/apt/sources.list:54 と /etc/apt/sources.list:57 で複数回設定されています
W: ターゲット DEP-11-icons (stable/dep11/icons-64x64.tar) は /etc/apt/sources.list:54 と /etc/apt/sources.list:57 で複数回設定されています
W: ターゲット Packages (stable/binary-all/Packages) は /etc/apt/sources.list:54 と /etc/apt/sources.list:57 で複数回設定されています
W: ターゲット Translations (stable/i18n/Translation-ja_JP) は /etc/apt/sources.list:54 と /etc/apt/sources.list:57 で複数回設定されています
W: ターゲット Translations (stable/i18n/Translation-ja) は /etc/apt/sources.list:54 と /etc/apt/sources.list:57 で複数回設定されています
W: ターゲット Translations (stable/i18n/Translation-en) は /etc/apt/sources.list:54 と /etc/apt/sources.list:57 で複数回設定されています
W: ターゲット DEP-11 (stable/dep11/Components-amd64.yml) は /etc/apt/sources.list:54 と /etc/apt/sources.list:57 で複数回設定されています
W: ターゲット DEP-11-icons (stable/dep11/icons-64x64.tar) は /etc/apt/sources.list:54 と /etc/apt/sources.list:57 で複数回設定されています

そこで当該ファイルを確認するために

cat /etc/apt/sources.list

とすると行末に

# deb-src [arch=armhf] https://download.docker.com/linux/ubuntu xenial stable
# deb-src [arch=armhf] https://download.docker.com/linux/ubuntu xenial stable edge test
deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable
# deb-src [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable

とあるので、誤ったリポジトリ(今回は[arch=armhf]とある2行)をエディタで編集して削除する。

docker-ceのインストール

以上二つの手続きを終えればdocker-ceのインストールが可能となる。

sudo apt install docker-ce

補足

Ubuntu 18.04 LTS 用の記事はこちらだが書いてあることは同じ。基本的に両者とも英語版の公式ドキュメントをなぞっているので最終的にはそちらを確認するのが安全。

7
4
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
7
4