2
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にDocker Engineをインストールする

Posted at

インストール方法の種類

dockerマニュアルによると、UbuntuにDocker Engineをインストールする方法は4つ存在します。

  • Docker Desktop for Linuxでインストール
  • Dockerのaptリポジトリからインストール
  • 手動でインストール
  • スクリプトでインストール

Dockerのaptリポジトリからインストールする方法を試してみました。

Dockerのaptリポジトリからインストール

基本的にdockerマニュアルに記載されているコマンドでインストールできました。

  1. Dockerのaptリポジトリをセットアップします。
# Dockerの公式GPGキーを追加します:
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /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

# リポジトリをAptソースに追加する:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] 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-get update
  1. Dockerパッケージをインストールします。
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
  1. hello-worldイメージを実行して、Docker Engineのインストールが成功したことを確認する。
sudo docker run hello-world

以下の確認メッセージが表示できれば、インストールOKになります。

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete
Digest: sha256:4bd78111b6914a99dbc560e6a20eab57ff6655aea4a80c50b0c5491968cbc2e6
Status: Downloaded newer image for hello-world:latest

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/

Dockerのstartとstop

$ ps -ef | grep docker
ubuntu    161685  160969  0 14:16 pts/1    00:00:00 grep --color=auto docker

$ sudo systemctl start docker

$ ps -ef | grep docker
root      161690       1  4 14:16 ?        00:00:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ubuntu    161832  160969  0 14:16 pts/1    00:00:00 grep --color=auto docker

$ sudo systemctl stop docker
Warning: Stopping docker.service, but it can still be activated by:
  docker.socket

$ ps -ef | grep docker
ubuntu    161838  160969  0 14:16 pts/1    00:00:00 grep --color=auto docker

参考情報

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