5
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.

Ubuntu 22.04にDocker Engine、Docker Composeをインストールする手順

Last updated at Posted at 2021-11-18

はじめに

Ubuntu 22.04にDocker Engine、Docker Composeをインストールする手順を、備忘録を兼ねて、まとめます。

  • クラウド、VPSなどの環境
  • Oracle VirtualBoxなどの仮想環境
  • WSL2の環境

等でインストールすることを想定しています。

Docker Engineをインストール

docker docsサイトのInstall Docker Engine on Ubuntuのページの手順でDockerをインストールします。

Docker Engineのリポジトリを設定

HTTPS上のリポジトリ使用に必要なaptパッケージのインストール

sudo apt update
sudo apt install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

Docker EngineのGPGキーを追加

sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

Docker Engineのaptリポジトリを登録

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Docker Engineをインストール

sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin

バージョンを確認

docker --version

結果(例):

Docker version 20.10.18, build b40c2f6

docker daemonを起動

sudo service docker start

自分のユーザーをdockerグループに所属させる

dockerグループを作成

sudo groupadd docker

※すでに存在しているエラーが表示されても、そのまま次以後の手順へ進みます。

現行ユーザをdockerグループに所属

sudo gpasswd -a $USER docker

dockerデーモン再起動

sudo service docker restart

exitして再ログイン

exit

再度SSHでログインすると、dockerグループへの所属が反映されます。

hello-world実行確認

hello-worldのコンテナ起動

sudo docker run hello-world

エラー等が発生せず、hello-worldのコンテナが正常に起動・終了することを確認します。

hello-worldのコンテナ削除

まず、先ほどの手順で作成されたコンテナを確認します。

docker ps -a

hello-worldのコンテナのIDを確認し、削除します。

docker rm {hello-world コンテナID}

hello-worldのイメージも使用しないため削除します。

docker rmi hello-world

Docker Composeインストール

Docker Composeをインストール

sudo apt update
sudo apt install docker-compose-plugin

バージョンを確認

docker compose version

結果(例):

Docker Compose version v2.5.0

以上の手順で、Docker EngineとDocker Composeを使えるようになります。

5
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
5
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?