見出し画像

【IT】Docker EngineとComposeのインストール(Ubuntu 22.04 LTS)

皆さま
こんにちは

本日は、Ubuntu に
Docker EngineとDocker Composeを導入します。
※Docker Desktopは、使用する環境で有料となったため導入はしません。

OSバージョンは、以下のものを使用します。

$ more /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.1 LTS"

Docker Engineのインストール

公式レポジトリを追加してセットアップします。
まず、aptでHTTPS経由でレポジトリを取得できるようにします。

$ sudo apt update
[sudo] password for testpy:
・
・
$ sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

次にDockerのofficial GPG keyを追加します。

$ sudo mkdir -p /etc/apt/keyrings
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

レポジトリを使える様にします。

$  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

レポジトリが設定できたらDockerEngineをインストールします。

$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  docker-ce-rootless-extras docker-scan-plugin libslirp0 pigz slirp4netns
Suggested packages:
  aufs-tools cgroupfs-mount | cgroup-lite
The following NEW packages will be installed:
  containerd.io docker-ce docker-ce-cli docker-ce-rootless-extras
  docker-compose-plugin docker-scan-plugin libslirp0 pigz slirp4netns
0 upgraded, 9 newly installed, 0 to remove and 62 not upgraded.
Need to get 111 MB of archives.
After this operation, 428 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
・
・
・

Docker Composeのインストール

Docker  Composeもインストールします。

$ sudo curl -SL https://github.com/docker/compose/releases/download/v2.15.1/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
[sudo] password for testpy:
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 42.8M  100 42.8M    0     0  11.0M      0  0:00:03  0:00:03 --:--:-- 12.1M
$ chmod +x /usr/local/bin/docker-compose

一般ユーザでのDockerコマンド許可

一般ユーザでも使える様にします。
今回のユーザ名は「testpy」とします。
※ここで注意は、-aオプション(追加)を忘れずに付与ください。

$ id testpy
uid=1001(testpy) gid=1001(testpy) groups=1001(testpy),27(sudo)
$ sudo usermod -aG docker testpy
$ id testpy
uid=1001(testpy) gid=1001(testpy) groups=1001(testpy),27(sudo),998(docker)

Dockerコマンドの動作確認

$ docker -v
Docker version 20.10.22, build 3a2c30b

$ docker run hello-world

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 ps -a
CONTAINER ID   IMAGE         COMMAND    CREATED         STATUS                     PORTS     NAMES
9d6c6868ec1f   hello-world   "/hello"   8 seconds ago   Exited (0) 7 seconds ago             dazzling_faraday
$ docker-compose -v
Docker Compose version v2.15.1


では

<<ご参考>> ※過去記事です。


この記事が気に入ったらサポートをしてみませんか?