在 Ubuntu20.04 上安装 Docker(也适用于 Ubuntu 22.04)
证明已经成功安装的证据。
(2022/7/30 附注:已确认在Ubuntu 22.04上也可以进行相同的安装)
(2022/8/17 附注:已添加关于设置用户权限和安装docker-compose的补充说明)
環境
-
- Ubuntu 20.04 LTS Desktop ja / Ubuntu 22.04 LTS Desktop ja
- Docker Community Edition (CE)
インストール方針
-
- sudo を使って Docker コマンドを動かす
-
- Ubuntu 標準レポジトリの Docker は使わない
- 公式 Docker レポジトリを使用して最新版を apt でインストールする
安装Docker
首先
「在Ubuntu 20.04上安装和使用Docker | DigitalOcean」
https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-20-04-ja
或者
「在Ubuntu 22.04上安装和使用Docker | DigitalOcean」
https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-22-04
の
「ステップ1— Dockerをインストールする」
照着这个方法继续前进。 .)
做好準備
$ sudo apt update
$ sudo apt install apt-transport-https ca-certificates curl software-properties-common
添加Docker存储库并可使用。
如果是Ubuntu 20.04的情况下
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
$ sudo apt update
在Ubuntu 22.04的情况下
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
$ echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
$ sudo apt update
我会确认可供安装的选项。
$ apt-cache policy docker-ce
docker-ce:
インストールされているバージョン: (なし)
候補: 5:20.10.7~3-0~ubuntu-focal
バージョンテーブル:
5:20.10.7~3-0~ubuntu-focal 500
500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
5:20.10.6~3-0~ubuntu-focal 500
500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
5:20.10.5~3-0~ubuntu-focal 500
500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
5:20.10.4~3-0~ubuntu-focal 500
500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
5:20.10.3~3-0~ubuntu-focal 500
500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
5:20.10.2~3-0~ubuntu-focal 500
500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
5:20.10.1~3-0~ubuntu-focal 500
500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
5:20.10.0~3-0~ubuntu-focal 500
500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
5:19.03.15~3-0~ubuntu-focal 500
500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
5:19.03.14~3-0~ubuntu-focal 500
500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
5:19.03.13~3-0~ubuntu-focal 500
500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
5:19.03.12~3-0~ubuntu-focal 500
500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
5:19.03.11~3-0~ubuntu-focal 500
500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
5:19.03.10~3-0~ubuntu-focal 500
500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
5:19.03.9~3-0~ubuntu-focal 500
500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
这个仓库是Docker的官方存储库。接下来,我们将安装Docker。
$ sudo apt install docker-ce
我要确认守护进程已经启动。
$ sudo systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2021-06-12 23:30:57 JST; 57s ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 167273 (dockerd)
Tasks: 13
Memory: 43.4M
CGroup: /system.slice/docker.service
└─167273 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
6月 12 23:30:56 nanbuwks-ThinkPad-X230 dockerd[167273]: time="2021-06-12T23:30:56.464426542+09:00" level=warning msg="Your kernel does not support CPU realtime sc>
6月 12 23:30:56 nanbuwks-ThinkPad-X230 dockerd[167273]: time="2021-06-12T23:30:56.464488380+09:00" level=warning msg="Your kernel does not support cgroup blkio we>
6月 12 23:30:56 nanbuwks-ThinkPad-X230 dockerd[167273]: time="2021-06-12T23:30:56.464508737+09:00" level=warning msg="Your kernel does not support cgroup blkio we>
6月 12 23:30:56 nanbuwks-ThinkPad-X230 dockerd[167273]: time="2021-06-12T23:30:56.464847077+09:00" level=info msg="Loading containers: start."
6月 12 23:30:56 nanbuwks-ThinkPad-X230 dockerd[167273]: time="2021-06-12T23:30:56.805499806+09:00" level=info msg="Default bridge (docker0) is assigned with an IP>
6月 12 23:30:57 nanbuwks-ThinkPad-X230 dockerd[167273]: time="2021-06-12T23:30:57.081790887+09:00" level=info msg="Loading containers: done."
6月 12 23:30:57 nanbuwks-ThinkPad-X230 dockerd[167273]: time="2021-06-12T23:30:57.202347194+09:00" level=info msg="Docker daemon" commit=b0f5bc3 graphdriver(s)=ov>
6月 12 23:30:57 nanbuwks-ThinkPad-X230 dockerd[167273]: time="2021-06-12T23:30:57.202660215+09:00" level=info msg="Daemon has completed initialization"
6月 12 23:30:57 nanbuwks-ThinkPad-X230 systemd[1]: Started Docker Application Container Engine.
6月 12 23:30:57 nanbuwks-ThinkPad-X230 dockerd[167273]: time="2021-06-12T23:30:57.277265072+09:00" level=info msg="API listen on /run/docker.sock"
$
试试看
你好,世界。
$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:7d246653d0511db2a6b2e0436cfd0e52ac8c066000264b3ce63331ac66dca625
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/
我正在进行动作。
$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c113fde343e6 hello-world "/hello" 47 seconds ago Exited (0) 44 seconds ago festive_mirza
khani
停止并删除测试。
$ sudo docker rm c113fde343e6
c113fde343e6
$ sudo docker rmi hello-world
Untagged: hello-world:latest
Untagged: hello-world@sha256:7d246653d0511db2a6b2e0436cfd0e52ac8c066000264b3ce63331ac66dca625
Deleted: sha256:feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412
Deleted: sha256:e07ee1baac5fae6a26f30cabfe54a36d3402f96afda318fe0a96cec4ca393359
$
「测试2」
「git-artes/docker-gnuradio」
https://github.com/git-artes/docker-gnuradio
目前最新版Ubuntu中含有GNU Radio(目前版本为3.8)的Docker容器(Ubuntu 18.04版本中包含3.7版本的容器)。
我会尝试使用(某物/某种方法)
(2022/09/14更新): 在途中遇到了tzdata卡住的问题。这不是docker安装的问题,而是需要在Dockerfile中进行相应的处理。如果只是进行简单的测试,最好还是仅使用之前的hello-world测试即可。
Configuring tzdata
------------------
Please select the geographic area in which you live. Subsequent configuration
questions will narrow this down by presenting a list of cities, representing
the time zones in which they are located.
1. Africa 3. Antarctica 5. Arctic 7. Atlantic 9. Indian 11. US
2. America 4. Australia 6. Asia 8. Europe 10. Pacific 12. Etc
Geographic area: 6
(编辑结束)
$ git clone https://github.com/git-artes/docker-gnuradio.git
Cloning into 'docker-gnuradio'...
remote: Enumerating objects: 17, done.
remote: Counting objects: 100% (17/17), done.
remote: Compressing objects: 100% (12/12), done.
remote: Total 17 (delta 6), reused 14 (delta 3), pack-reused 0
Unpacking objects: 100% (17/17), 4.27 KiB | 729.00 KiB/s, done.
$ cd docker-gnuradio/
$ ls -alh
合計 64K
drwxrwxr-x 5 nanbuwks nanbuwks 4.0K 6月 12 23:35 .
drwxr-xr-x 49 nanbuwks nanbuwks 36K 6月 12 23:35 ..
drwxrwxr-x 8 nanbuwks nanbuwks 4.0K 6月 12 23:35 .git
-rw-rw-r-- 1 nanbuwks nanbuwks 846 6月 12 23:35 LICENSE
-rw-rw-r-- 1 nanbuwks nanbuwks 2.9K 6月 12 23:35 README.md
drwxrwxr-x 2 nanbuwks nanbuwks 4.0K 6月 12 23:35 gnuradio-releases
drwxrwxr-x 2 nanbuwks nanbuwks 4.0K 6月 12 23:35 gnuradio-releases-37
$ cd gnuradio-releases
$ sudo docker build -t ubuntu:gnuradio-releases .
需要一些时间。
$ sudo docker run --net=host --env="DISPLAY" --volume="$HOME/.Xauthority:/root/.Xauthority:rw" --device /dev/snd -v persistent:/home/gnuradio/persistent --group-add=audio -it ubuntu:gnuradio-releases bash
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.
gnuradio@nanbuwks-ThinkPad-X230:~$ cat /etc/issue
Ubuntu 20.04.2 LTS \n \l
gnuradio@nanbuwks-ThinkPad-X230:~$ ls
persistent
开始运动了
设置用户权限
$ sudo usermod -aG docker $USER
作为重新启动的选项。
安装Docker Compose。
$ sudo apt install docker-compose
インストール後の使い方?
$ docker stop $(docker ps -q)
で止めた後、再度Docker環境に入ろうとしても
$ docker exec -it ardublock2204 /bin/bash
Error response from daemon: Container a58cbb91a560faf5c7e9c59f290922ab5a6b3bfc0350e3296cfd23411a2fb860 is not running
not runnning となる。
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a58cbb91a560 ubuntu:22.04 "bash" 3 days ago Exited (137) 10 minutes ago ardublock2204
Exited となっているので、以下のようにして起動すると入れるようになる。
$ docker start ardublock2204