ubuntuにdockerをインストールする方法

この記事通りで行けた。

UbuntuにDockerをインストールする手順 - Qiita

6 apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
7 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key
8 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
9 add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
10 apt-get update
11 apt-get install -y docker-ce docker-ce-cli containerd.io
12 apt-get update
13 gpasswd -a yaju docker
14 docker -v
15 history

エラーが出る場合

ディレクトリ /var/lib/apt/lists/ をロックできません

yaju@yaju-PRIMERGY-TX1310-M3:~$ sudo apt-get update
[sudo] password for yaju:
パッケージリストを読み込んでいます... 完了
E: Could not get lock /var/lib/apt/lists/lock. It is held by process 21971 (aptd)
N: Be aware that removing the lock file is not a solution and may break your system.
E: ディレクトリ /var/lib/apt/lists/ をロックできません

↓lock ファイル削除後、解消

yaju@yaju-PRIMERGY-TX1310-M3:~$ sudo rm /var/lib/apt/lists/lock
yaju@yaju-PRIMERGY-TX1310-M3:~$ sudo rm /var/lib/dpkg/lock
yaju@yaju-PRIMERGY-TX1310-M3:~$ sudo apt-get update
ヒット:1 http://jp.archive.ubuntu.com/ubuntu jammy InRelease
取得:2 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
取得:3 http://jp.archive.ubuntu.com/ubuntu jammy-updates InRelease [119 kB]
取得:4 http://jp.archive.ubuntu.com/ubuntu jammy-backports InRelease [107 kB]
取得:5 http://jp.archive.ubuntu.com/ubuntu jammy-updates/main amd64 c-n-f Metadata [13.6 kB]
349 kB を 2秒 で取得しました (184 kB/s)
パッケージリストを読み込んでいます... 完了

[Ubuntu][apt] /var/lib/apt/lists/lockが不正な状態になった場合の対応メモ - Qiita

Could not resolve host: download.docker.com

yaju@yaju-PRIMERGY-TX1310-M3:~$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
curl: (6) Could not resolve host: download.docker.com
gpg: no valid OpenPGP data found.

curl -fsSL https://download.docker.com/linux/ubuntu/gpg -x http://プロキシ:ポート番号/ | sudo apt-key add -

のように、-xオプションとプロキシの指定が必要。

yaju@yaju-PRIMERGY-TX1310-M3:~$ curl -fsSL [https://download.docker.com/linux/ubuntu/gpg](https://download.docker.com/linux/ubuntu/gpg) -x [http://10.255.254.11:8080/](http://10.255.254.11:8080/) | sudo apt-key add -
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
OK

Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).

apt-keyが非推奨だよって言っているだけなので、一旦コマンドは通ってる。

proxy環境でDockerを使用するときの設定

docker-composeを入れるなら?

sudo apt install docker-compose

入ってるか確認

yaju@yaju-PRIMERGY-TX1310-M3:~$ docker-compose -v
docker-compose version 1.29.2, build unknown

プロキシ環境で最新版のdocker-composeをインストールしたい場合

何を頑張ってもプロキシを超えられなかったので、

https://github.com/docker/compose/releases/tag/v2.17.0

にWindowsでアクセス

docker-compose-linux-x86_64をダウンロード

がんばってubuntuの/usr/local/bin/docker-composeに配置

sudo chmod +x /usr/local/bin/docker-compose

これで、docker-compose -vコマンドを実行してバージョンがv2.17.0になっていることを確認できます。

wls2環境でビルドできない場合

docker-compose up -dすると

docker.errors.DockerException: Error while fetching server API version: ('Connection aborted.', ConnectionRefusedError(111, 'Connection refused'))

トなってしまう場合。

下記で解決する。
【WSL2】DockerでCannot connect to the Docker daemon…と表示される問題の対処 | ReMIXのブログ

無制限に質問可能なプログラミングスクール!

万が一転職できない場合は、転職保障全額返金できるコースもあり!!

無制限のメンター質問対応

 

DMMウェブキャンプでプログラミングを学習しませんか?

独学より成長スピードをブーストさせましょう!

 

まずは無料相談から!

おすすめの記事