Linux(Ubuntu)にDockerとDocker Composeをインストールする

4月 10, 2024

便利なオープンソースなツールをインストールしようとしたとき、Dockerが前提になっていることが多くなってきました。ということでDockerとDocker ComposeをUbuntu20.04にインストールします。


sudo apt-get update
sudo apt-get install ca-certificates curl


sudo curl -fsSL -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc


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


sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli


root@ip-172-31-7-75:~# apt-get update
Hit:1 focal InRelease
Hit:2 focal-updates InRelease
Hit:3 focal-backports InRelease
Hit:4 stable InRelease
Get:5 focal InRelease [57.7 kB]
Get:6 focal-security InRelease [114 kB]
Get:7 focal/stable amd64 Packages [15.5 kB]
Fetched 187 kB in 1s (306 kB/s)
Reading package lists… Done

root@ip-172-31-7-75:~# apt-get install docker-ce docker-ce-cli
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following additional packages will be installed:
docker-ce-rootless-extras docker-scan-plugin pigz slirp4netns
Suggested packages:
aufs-tools cgroupfs-mount | cgroup-lite
The following NEW packages will be installed: docker-ce docker-ce-cli docker-ce-rootless-extras
docker-scan-plugin pigz slirp4netns
0 upgraded, 7 newly installed, 0 to remove and 0 not upgraded.
Need to get 96.4 MB of archives.
After this operation, 405 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 focal/universe amd64 pigz amd64 2.4-1 [57.4 kB]
Get:2 focal/universe amd64 slirp4netns amd64 0.4.3-1 [74.3 kB]
Get:3 focal/stable amd64 amd64 1.5.11-1 [22.9 MB]
Get:4 focal/stable amd64 docker-ce-cli amd64 5:20.10.14~3-0~ubuntu-focal [41.0 MB]
Get:5 focal/stable amd64 docker-ce amd64 5:20.10.14~3-0~ubuntu-focal [20.9 MB]
Get:6 focal/stable amd64 docker-ce-rootless-extras amd64 5:20.10.14~3-0~ubuntu-focal [7932 kB]
Get:7 focal/stable amd64 docker-scan-plugin amd64 0.17.0~ubuntu-focal [3521 kB]
Fetched 96.4 MB in 2s (40.1 MB/s)
Selecting previously unselected package pigz.
(Reading database … 127271 files and directories currently installed.)
Preparing to unpack …/0-pigz_2.4-1_amd64.deb …
Unpacking pigz (2.4-1) …
Selecting previously unselected package
Preparing to unpack …/1-containerd.io_1.5.11-1_amd64.deb …
Unpacking (1.5.11-1) …
Selecting previously unselected package docker-ce-cli.
Preparing to unpack …/2-docker-ce-cli_5%3a20.10.14~3-0~ubuntu-focal_amd64.deb …
Unpacking docker-ce-cli (5:20.10.14~3-0~ubuntu-focal) …
Selecting previously unselected package docker-ce.
Preparing to unpack …/3-docker-ce_5%3a20.10.14~3-0~ubuntu-focal_amd64.deb …
Unpacking docker-ce (5:20.10.14~3-0~ubuntu-focal) …
Selecting previously unselected package docker-ce-rootless-extras.
Preparing to unpack …/4-docker-ce-rootless-extras_5%3a20.10.14~3-0~ubuntu-focal_amd64.deb …
Unpacking docker-ce-rootless-extras (5:20.10.14~3-0~ubuntu-focal) …
Selecting previously unselected package docker-scan-plugin.
Preparing to unpack …/5-docker-scan-plugin_0.17.0~ubuntu-focal_amd64.deb …
Unpacking docker-scan-plugin (0.17.0~ubuntu-focal) …
Selecting previously unselected package slirp4netns.
Preparing to unpack …/6-slirp4netns_0.4.3-1_amd64.deb …
Unpacking slirp4netns (0.4.3-1) …
Setting up slirp4netns (0.4.3-1) …
Setting up docker-scan-plugin (0.17.0~ubuntu-focal) …
Setting up (1.5.11-1) …
Created symlink /etc/systemd/system/ → /lib/systemd/system/containerd.service.
Setting up docker-ce-cli (5:20.10.14~3-0~ubuntu-focal) …
Setting up pigz (2.4-1) …
Setting up docker-ce-rootless-extras (5:20.10.14~3-0~ubuntu-focal) …
Setting up docker-ce (5:20.10.14~3-0~ubuntu-focal) …
Created symlink /etc/systemd/system/ → /lib/systemd/system/docker.service.
Created symlink /etc/systemd/system/ → /lib/systemd/system/docker.socket.
Processing triggers for man-db (2.9.1-1) …
Processing triggers for systemd (245.4-4ubuntu3.15) …


systemctl enable docker.service
systemctl enable containerd.service

次はDocker Composeをインストールします。

Docker Composeの最新版を指定したディレクトリにダウンロードします。

curl -L`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

root@ip-172-31-7-75:~# curl -L -suname -m -o /usr/local/bin/docker-compose
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 664 100 664 0 0 5398 0 –:–:– –:–:– –:–:– 5398
100 25.2M 100 25.2M 0 0 41.4M 0 –:–:– –:–:– –:–:– 41.4M



chmod +x /usr/local/bin/docker-compose


docker-compose --version

root@ip-172-31-7-75:~# docker-compose –version
Docker Compose version v2.4.1


Posted by admin