0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【後編】Docker環境を作る

Last updated at Posted at 2025-10-07

こんにちは。ここではDockerを実際に構築していきます。Dockerのことよく知らない方は先に【前編】の説明を読むことをおすすめします。

前準備

必要パッケージのインストール

sudo apt install -y ca-certificates curl gnupg

GPGキーの登録

gpgはGNU Privacy Guard (GnuPG, GPG)の略で暗号化ソフトウェアです.
暗号化だけでなく署名や認証といったオンライン上の機密や信用を管理するツールとしても利用されます.特徴として公開鍵暗号方式を使用しますが,その鍵の管理のために,認証局を設置しません.各利用者の責任で鍵を管理し,取得した公開鍵をチェックします.

sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

aptリポジトリの追加&更新

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

sudo apt update

Dockerのパッケージインストール

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

動作確認

dockerの起動

sudo systemctl start docker
sudo systemctl enable docker
sudo systemctl status docker

Active: active (running)を確認すること

dockerを確認

sudo docker run hello-world

出力結果の真ん中くらいに下の文があれば完璧

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

補足 (docker run hello-worldについて)

この起動コードはDockerのパッケージやシステムがちゃんと動いているかテストできます。Dockerは以下のステップで出力を返します。

  1. Dockerデーモンが動く
  2. イメージをpullする
  3. コンテナを起動する
  4. 出力を返す

先のコードはコンテナを瞬間的に起動させてすぐ終了させるので死骸が残ってます。

$ sudo docker ps -a
CONTAINER ID   IMAGE         COMMAND    CREATED         STATUS                     PORTS     NAMES
fde8445f7876   hello-world   "/hello"   5 minutes ago   Exited (0) 5 minutes ago             hopeful_rosalind

まあ目障りなので消しておきます。

$ sudo docker rm hopeful_rosalind

参考

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?