Docker簡介與安裝
- Docker簡介
- Docker的安裝
- 卸載舊版本
- 使用腳本安裝
- 啟動Docker
- 測驗Docker是否安裝
- 出現問題的解決方法
- 1 問題描述
- 2 原因分析
- 3 解決方法
- 4 檢查是否更新成功
- References
Docker簡介
Docker 使用 Google 公司推出的 Go 語言 (opens new window)進行開發實作,基于 Linux 內核的 cgroup (opens new window),namespace (opens new window),以及 OverlayFS (opens new window)類的 Union FS (opens new window)等技術,對行程進行封裝隔離,屬于 作業系統層面的虛擬化技術 (opens new window),由于隔離的行程獨立于宿主和其它的隔離的行程,因此也稱其為容器,

runc是一個linux命令運行工具,用于根據OCI容器運行時規范(opens new windows)創建和運行容器
containerd是一個守護程式,管理容器生命周期
Docker 在容器的基礎上,進行了進一步的封裝,從檔案系統、網路互聯到行程隔離等等,極大的簡化了容器的創建和維護,使得 Docker 技術比虛擬機技術更為輕便、快捷,

Docker的安裝
Docker 可以安裝在 64 位的 x86 平臺或 ARM 平臺上,Ubuntu 發行版中,LTS(Long-Term-Support)長期支持版本,會獲得 5 年的升級維護支持,這樣的版本會更穩定,因此在生產環境中推薦使用 LTS 版本,此次運行的作業系統是ubuntu 20.04
卸載舊版本
舊版本的 Docker 稱為docker或者docker-engine,使用以下命令卸載舊版本:
$ sudo apt-get remove docker \
docker-engine \
docker.io
使用腳本安裝
在測驗或開發環境中 Docker 官方為了簡化安裝流程,提供了一套便捷的安裝腳本,Ubuntu 系統上可以使用這套腳本安裝,另外可以通過--mirror選項使用國內源進行安裝:
若你想安裝測驗版的 Docker, 請從 test.docker.com 獲取腳本
# $ curl -fsSL test.docker.com -o get-docker.sh
$ curl -fsSL get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh --mirror Aliyun
# $ sudo sh get-docker.sh --mirror AzureChinaCloud
執行這個命令后,腳本就會自動的將一切準備作業做好,并且把 Docker 的穩定(stable)版本安裝在系統中,
啟動Docker
$ sudo systemctl enable docker
$ sudo systemctl start docker
測驗Docker是否安裝
$ docker run --rm hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:308866a43596e83578c7dfa15e27a73011bdd402185a84c5cd7f32a88b501a24
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/
若能正常輸出以上資訊,則說明安裝成功,
出現問題的解決方法
1 問題描述
在終端執行"docker version"命令,出現如下報錯:
“Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.26/images/json: dial unix /var/run/docker.sock: connect: permission denied”
2 原因分析
docker行程使用 Unix Socket 而不是 TCP 埠,而默認情況下,Unix socket 屬于 root 用戶,因此需要 root權限 才能訪問,
3 解決方法
sudo groupadd docker #添加docker用戶組
sudo gpasswd -a $XXX docker #檢測當前用戶是否已經在docker用戶組中,其中XXX為用戶名,例如我的,liangll
sudo gpasswd -a $USER docker #將當前用戶添加至docker用戶組
newgrp docker #更新docker用戶組
4 檢查是否更新成功
再次執行"docker version"命令,發現不再出現"Got permission denied"權限報錯

References
感謝datawhale的資料datawhale的Docker
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/275094.html
標籤:其他
上一篇:行程
下一篇:【Linux 2】常用指令
