Ubuntu(22.04)+Docker環境構築

Published by

on

項目バージョン
OSUbuntu 22.04.03 LTS
Docker25.0.3
確認環境

Ubuntu環境でコンテナ型仮想化ソフトウェアである「Docker」を導入してみます。本記事では、Dockerのセットアップから簡単な動作確認までを実施することとします。

■1.インストールに必要なパッケージの準備

「sudo apt install」では確認が表示されるので「Y」を指定して続行します。

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

■2.Dockerインストール前準備

Dockerパッケージをパッケージマネージャからインストールするにあたり、公開鍵を用いて検証を行う準備をします。具体的には鍵をaptへ登録します。以下の2つ目のコマンド実行で、鍵をダウンロードし、変換したうえでaptの鍵の保管場所へ登録します。3つ目のコマンドで参照できるよう権限設定を変更します。

cd /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

■3.aptパッケージマネージャにdocker取得先を追加

docker取得先をaptに登録して、2つ目のコマンドで検出を行います。

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
sudo apt update

■4.インストール

ようやく実際のインストールにたどり着きました。Dockerエンジンのデーモン、操作用クライアント、コンテナランタイムソフトウェアの3つを指定してインストールします。

sudo apt install docker-ce docker-ce-cli containerd.io

■5.インストール後確認

インストールが正常にしているかどうかをバージョン表示と「hello-world」コンテナの実行をもって確認します。

sudo docker --version

上記コマンドの結果、「Docker version 25.0.3, build xxxxxx」のような表示がでればOKです。次に「hello-world」コンテナを実行してDockerエンジンが正しくセットアップされているか確認します。

sudo docker run hello-world

実行した結果、以下のような表示がされれば、OKと判断できます。

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/

For more examples and ideas, visit:
https://docs.docker.com/get-started/

とりあえず、今回はここまでとします。

“Ubuntu(22.04)+Docker環境構築”. への1件のコメント

  1. […] Dockerのセットアップは別記事の「Ubuntu+Docker環境構築」(https://note2self.blog/2024/02/16/ubuntudocker%e7%92%b0%e5%a2%83%e6%a7%8b%e7%af%89/)を参照ください。 […]

    いいね

Laravel開発環境構築 – note2self への返信 コメントをキャンセル