LoginSignup
4
0

More than 1 year has passed since last update.

UbuntuにDockerをインストールする手順

Last updated at Posted at 2022-04-20

事前知識

UbuntuにDockerをインストールする手順

1.パッケージをアップデートする

  • コマンド
sudo apt-get update
  • 実行例
$ sudo apt-get update
[sudo] password for ユーザ名:
ヒット:1 http://jp.archive.ubuntu.com/ubuntu focal InRelease

2.必要なパッケージをインストールする
- Do you want to continue? [Y/n] が表示されたら、 y を入力する

  • コマンド
sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
  • 実行例
$ sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了

3.キーを登録

  • コマンド
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key
  • 実行例
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
OK

4.ダウンロードサイトをaptリポジトリに登録

  • コマンド
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
  • 実行例
$ sudo add-apt-repository \
> "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
> $(lsb_release -cs) \
> stable"
ヒット:1 http://jp.archive.ubuntu.com/ubuntu focal InRelease
取得:2 https://download.docker.com/linux/ubuntu focal InRelease [57.7 kB]
ヒット:3 http://jp.archive.ubuntu.com/ubuntu focal-updates InRelease

5.Docker Engine一式をインストール

  • コマンド
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
  • 実行例
$ sudo apt-get update
ヒット:1 http://jp.archive.ubuntu.com/ubuntu focal InRelease
ヒット:2 http://jp.archive.ubuntu.com/ubuntu focal-updates InRelease
ヒット:3 http://jp.archive.ubuntu.com/ubuntu focal-backports InRelease
ヒット:4 https://download.docker.com/linux/ubuntu focal InRelease
ヒット:5 http://security.ubuntu.com/ubuntu focal-security InRelease
パッケージリストを読み込んでいます... 完了
$ sudo apt-get install -y docker-ce docker-ce-cli containerd.io
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
以下の追加パッケージがインストールされます:
  docker-ce-rootless-extras docker-scan-plugin git git-man liberror-perl pigz slirp4netns

6.Dockerを利用できるようにする

  • コマンド
sudo gpasswd -a ユーザ名 docker
  • 実行例
$ sudo gpasswd -a ユーザ名 docker
Adding user ユーザ名 to group docker

7.ログオフする

  • コマンド
exit

8.Dockerのバージョン確認

  • コマンド
docker -v
  • 実行例
$ docker -v
Docker version 20.10.12, build e91ed57

wsl2のUbuntuを使用してDockerコマンド実行時にエラーが出た場合

以下のエラーが発生した場合、Docker再起動を行う。

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Docker再起動

  • コマンド
service docker stop // Docker停止
service docker start // Docker開始
  • 実行結果
$ sudo service docker stop
 * Docker already stopped - file /var/run/docker-ssd.pid not found.
$ sudo service docker start
 * Starting Docker: docker
4
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
4
0