本記事では本記事では、Ubuntu 22.04を例にLinux環境へDockerをインストールする方法を、初心者向けに解説します。コマンドの意味や、インストール後の確認方法、よくあるエラー対処まで網羅しています。
管理人本記事の読者層は以下の方を想定しています。
- Dockerを利用したことのない方
Dockerとは?(初心者向け)
サーバー用のアプリケーションを、サーバー本体に直接インストールするのではなく、「コンテナ」と呼ばれる技術を使って仮想的な実行環境を構築する方法があることをご存じでしょうか。
Linuxによるサーバー構築は、Windows Server や Windows Home/Professional と比較して柔軟性が高い一方で、環境構築の難易度が高いことでも知られています。しかし、一度構築してしまえば、セキュリティ面に優れ、拡張性の高いサービスを提供できる点が Linux サーバーの大きな特徴です。
一方で、サーバー本体のハードウェア故障や、OSのバージョンアップに伴う不具合が発生した場合、環境を一から再構築するには多大な時間と労力が必要になります。もし、構築済みのサーバー環境をそのまま保存し、別のサーバーやOSへ簡単に移行できたとしたら、運用は大きく効率化されるでしょう。
コンテナは環境ごと持ち運びが可能なため、サーバー障害が発生した場合でも、事前に用意しておいたコンテナを別のホスト上で起動するだけで、短時間で復旧作業を完了できます。また、同じコンテナを異なるサーバーやOS上で実行できる点も、大きなメリットです。
このように、サーバー環境を「容器(コンテナ)」として扱えることが、Dockerをはじめとするコンテナ技術の最大の利点と言えるでしょう。
必要環境
「Docker」の優れたところは、他のOSでも同じ環境でサーバー構築ができるところにあります。
まず、その環境構築を行うための基本についてお伝えします。
まず、「Docker」はパッケージで提供されており、以下のOS環境にインストールができます。
使用環境
- Linux OS (本記事ではUbuntu)
- Windows OS (WSL2)
- macOS (M1を含む)
Linux (ubuntu) や Windows, macOS上でも「Docker」をインストールすれば同じイメージファイルで同じ環境構築が可能です。
本記事では、「Linux Ubuntu 22.04 LTS」の環境化で「Docker」インストールする方法を紹介します。
使用環境
- ホスト環境:Windows OS 10もしくは11
- 仮想環境マシン:WSL(Windows Subsystem for Linux) 1 もしくはWSL 2 (どちらでも)
- 仮想環境OS:Ubuntu 22.04 LTS
- Docker (Linux Ubuntu 22.04 LTS) バージョン 20.21
一方で、各OS上での「Docker」のインストールについては以下の記事をご参照ください。
Windows上で動作するWSL2上にDockerをインストールする方法の解説


macOSにDockerをインストールする方法の解説


公式リポジトリからDockerをインストールする手順
それでは、Linux環境下でDockerをインストールする方法をご紹介します。Linux環境化のターミナル画面から以下の手順に従ってインストールを行ってください。
Dockerのリポジトリを追加
①updateとupgradeを行っておきます。
$ sudo apt-get update
$ sudo apt-get upgrade②必要なパッケージをインストール
$ sudo apt install -y \
ca-certificates \
curl \
gnupg \
lsb-release③次に、Dockerの公式GPGキーを追加します。OKとでれば問題ありません。
$ 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公式リポジトリを追加
$ 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 -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
⑥ Dockerの起動確認と有効化
$ sudo systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset>
Active: active (running) since Thu 2025-12-18 19:41:35 JST; 1min 15s ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 38946 (dockerd)
Tasks: 14
Memory: 24.9M
CPU: 401ms
CGroup: /system.slice/docker.service
mq38946 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/con>
12月 18 19:41:34 toruqe dockerd[38946]: time="2025-12-18T19:41:34.451991504+09:>
12月 18 19:41:34 toruqe dockerd[38946]: time="2025-12-18T19:41:34.563704630+09:>
12月 18 19:41:34 toruqe dockerd[38946]: time="2025-12-18T19:41:34.576573006+09:>
12月 18 19:41:35 toruqe dockerd[38946]: time="2025-12-18T19:41:35.163270910+09:>
12月 18 19:41:35 toruqe dockerd[38946]: time="2025-12-18T19:41:35.171111999+09:>
12月 18 19:41:35 toruqe dockerd[38946]: time="2025-12-18T19:41:35.171248497+09:>
12月 18 19:41:35 toruqe dockerd[38946]: time="2025-12-18T19:41:35.267731066+09:>
12月 18 19:41:35 toruqe dockerd[38946]: time="2025-12-18T19:41:35.275486604+09:>
12月 18 19:41:35 toruqe dockerd[38946]: time="2025-12-18T19:41:35.275636257+09:>
12月 18 19:41:35 toruqe systemd[1]: Started Docker Application Container Engine.
⑦Dockerサービスを「自動起動対象」として systemd に登録します。
「OS起動時に Docker デーモン(dockerd)を自動起動するよう登録する」コマンドです。
$ sudo systemctl enable docker
Synchronizing state of docker.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable dockerコマンドラインからDockerのインストール状況確認
①インストールが完了できたか確認するために、Dockerのバージョンを確認します。
$ docker --version
Docker version 29.1.3, build f52814d
$ docker compose version
Docker Compose version v5.0.0②次にDockerのサービスを開始させます。
$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
17eec7bbc9d7: Pull complete
ea52d2000f90: Download complete
Digest: sha256:d4aaab6242e0cace87e2ec17a2ed3d779d18fbfd03042ea58f2995626396a274
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のグループ作成
①Dockerのコマンドにはsudoが必要になります。sudoを使用せずに dockerを使いたい場合には、dockerという名前のグループをつくり、ユーザーをそこにに所属させれば良いです。ここで、以下のようにグループを作成します。
$ sudo groupadd docker②現行ユーザーをdockerグループに所属させます。以下のようにユーザー(misato)を追加した場合です。
sudo gpasswd -a misato docker③Linux ではまた、以下のコマンドによってグループ変更を行うこともできます。その後パスワードが聞かれます。
newgrp docker④dockerサービスを再起動する
$ sudo service docker restartDockerのコンテナ格納先
Dockerのコンテナ格納先はdocker infoコマンドで確認できます。
$ sudo docker info
Client: Docker Engine - Community
Version: 29.1.3
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc.)
Version: v0.30.1
Path: /usr/libexec/docker/cli-plugins/docker-buildx
compose: Docker Compose (Docker Inc.)
Version: v5.0.0
Path: /usr/libexec/docker/cli-plugins/docker-compose
Server:
Containers: 1
Running: 0
Paused: 0
Stopped: 1
Images: 1
Server Version: 29.1.3
Storage Driver: overlayfs
driver-type: io.containerd.snapshotter.v1
Logging Driver: json-file
Cgroup Driver: systemd
Cgroup Version: 2
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
CDI spec directories:
(中略)
Docker Root Dir: /var/lib/dockerdocker info の出力結果から、Dockerのストレージ設定について以下の点が確認できます。
- コンテナやイメージなどの Dockerデータの保存先(Docker Root Dir) は
/var/lib/dockerである。 - Storage Driver には Linux カーネルの overlayfs が使用されている。
よくあるトラブルと解決方法
Dockerサービスが起動していない
以上のようなエラーが出た場合
Cannot connect to the Docker daemon確認方法
systemctl status docker解決方法
sudo systemctl start docker
sudo systemctl enable dockerDocker上で様々なサーバーを立ち上げる方法
Dockerを利用してサーバーアプリとして人気のある「nextcloud」や「WordPress」をインストールする方法を以下でもご紹介しています。こちらも是非ご覧下さい。
nextcloudをサーバーへインストール方法の解説


WordPressをサーバーへインストール方法の解説


まとめ
本記事では、DockerをLinux上にインストールする方法を解説しました。
- インストールしたDockerは無償版であるDocker CE(Community Edition)です。。
- インストール先はLinux Ubuntu 18.04Dockerのイメージファイルの保存先は、
/var/lib/dockerとなります。。 - Dockerを利用することで「mySQLサーバー」や「httpサーバー」を簡単にインストールできます。更にこれらを複合的に利用した「nextcloud」や「wordPress」もインストーが容易にできます。
次回の記事をご期待下さい。どうぞよろしくお願いいたします。
関連リンク








コメント