Ubuntu安装docker
Ubuntu安装docker
环境:
root@root:/etc/apt# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.2 LTS
Release: 20.04
Codename: focal
修改IP为静态IP:
vim /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
ethernets:
ens160:
addresses: [192.168.1.116/24]
dhcp4: no
optional: true
gateway4: 192.168.1.1
nameservers:
addresses: [114.114.114.114,223.5.5.5]
version: 2
renderer: networkd
编辑Yaml文件时,请确保遵循YAML代码缩进标准。 如果语法不正确,则更改将不会应用。
完成后,运行以下命令,保存文件并应用更改:
sudo netplan apply
ubuntu@shenzhen $ cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
# 127.0.0.53 is the systemd-resolved stub resolver.
# run "systemd-resolve --status" to see details about the actual nameservers.
nameserver 127.0.0.53
options timeout:2 attempts:3 rotate single-request-reopen
这个意思好像就是systemd-resolved在本地自建了一个本地DNS服务器,它的上游可以通过resolvectl命令来查看,这有点类似于一些著名代理客户端的在本地的那些操作。我们可以不必修改这个127.0.0.53而花精力去研究这个systemd-resolved,它的命令行工具是resolvectl,我们应该研究它。需要找文档时可以man resolv再按几下tab就可以找到DNS相关文档。另外我建议,对于这些ubuntu的蜜汁操作,研究起来可能确实有点麻烦,我们可以花更多的功夫去研究Centos或者Debian的相关内容
通过键入以下内容验证更改:
ip addr show dev ens160
ping www.baidu.com
修改为国内源
我下边以清华源为例
编辑/etc/apt/sources.list文件, 在文件最前面添加以下条目(操作前请做好相应备份):
cd /etc/apt
cp sources.list{,.bak}
egrep -v "#|$" sources.list.bak > sources.list
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
更新一下
sudo apt-get update
sudo apt-get upgrade
安装docker
安装前准备
官方文档:https://docs.docker.com/engine/install/
清华源Docker Community Edition 镜像使用帮助文档:https://mirrors.tuna.tsinghua.edu.cn/help/docker-ce/
安装过程
首先安装依赖:
sudo apt-get -y install apt-transport-https ca-certificates curl gnupg2 software-properties-common
信任 Docker 的 GPG 公钥:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
对于 amd64 架构的计算机,添加软件仓库:
sudo add-apt-repository \
"deb [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu \
$(lsb_release -cs) \
stable"
最后安装
sudo apt-get -y update
sudo apt-get -y install docker-ce docker-ce-cli
查找Docker-CE的版本:
root@root:~# sudo apt-cache madison docker-cedocker-ce | 5:20.10.6~3-0~ubuntu-focal | https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 Packages docker-ce | 5:20.10.5~3-0~ubuntu-focal | https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 Packages docker-ce | 5:20.10.4~3-0~ubuntu-focal | https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 Packages docker-ce | 5:20.10.3~3-0~ubuntu-focal | https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 Packages docker-ce | 5:20.10.2~3-0~ubuntu-focal | https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 Packages docker-ce | 5:20.10.1~3-0~ubuntu-focal | https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 Packages docker-ce | 5:20.10.0~3-0~ubuntu-focal | https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 Packages docker-ce | 5:19.03.15~3-0~ubuntu-focal | https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 Packages docker-ce | 5:19.03.14~3-0~ubuntu-focal | https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 Packages docker-ce | 5:19.03.13~3-0~ubuntu-focal | https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 Packages docker-ce | 5:19.03.12~3-0~ubuntu-focal | https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 Packages docker-ce | 5:19.03.11~3-0~ubuntu-focal | https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 Packages docker-ce | 5:19.03.10~3-0~ubuntu-focal | https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 Packages docker-ce | 5:19.03.9~3-0~ubuntu-focal | https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 Packages
安装指定版本的Docker-CE:
sudo apt-get -y install docker-ce=[VERSION] docker-ce-cli=[VERSION]
示例:
sudo apt-get -y install docker-ce=5:20.10.63-0ubuntu-focal docker-ce-cli=5:20.10.63-0ubuntu-focal
删除docker
apt purge docker-ce
rm -rf /var/lib/docker
查看docker版本
root@root:~# docker versionClient: Docker Engine - Community Version: 20.10.6 API version: 1.41 Go version: go1.13.15 Git commit: 370c289 Built: Fri Apr 9 22:47:17 2021 OS/Arch: linux/amd64 Context: default Experimental: trueServer: Docker Engine - Community Engine: Version: 20.10.6 API version: 1.41 (minimum version 1.12) Go version: go1.13.15 Git commit: 8728dd2 Built: Fri Apr 9 22:45:28 2021 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.4.4 GitCommit: 05f951a3781f4f2c1911b05e61c160e9c30eaa8e runc: Version: 1.0.0-rc93 GitCommit: 12644e614e25b05da6fd08a38ffa0cfe1903fdec docker-init: Version: 0.19.0 GitCommit: de40ad0
查看docker详细信息
root@root:~# docker infoClient: Context: default Debug Mode: false Plugins: app: Docker App (Docker Inc., v0.9.1-beta3) buildx: Build with BuildKit (Docker Inc., v0.5.1-docker) scan: Docker Scan (Docker Inc., v0.7.0)Server: Containers: 0 Running: 0 Paused: 0 Stopped: 0 Images: 0 Server Version: 20.10.6 Storage Driver: overlay2 Backing Filesystem: extfs Supports d_type: true Native Overlay Diff: true userxattr: false Logging Driver: json-file Cgroup Driver: cgroupfs Cgroup Version: 1 Plugins: Volume: local Network: bridge host ipvlan macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog Swarm: inactive Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc Default Runtime: runc Init Binary: docker-init containerd version: 05f951a3781f4f2c1911b05e61c160e9c30eaa8e runc version: 12644e614e25b05da6fd08a38ffa0cfe1903fdec init version: de40ad0 Security Options: apparmor seccomp Profile: default Kernel Version: 5.4.0-72-generic Operating System: Ubuntu 20.04.2 LTS OSType: linux Architecture: x86_64 CPUs: 4 Total Memory: 3.843GiB Name: root ID: 52WH:SLV3:OOUY:WY2Z:RQMZ:WR76:E5TF:QTOC:ABW2:TRH7:XE55:FBBD Docker Root Dir: /var/lib/docker Debug Mode: false Registry: https://index.docker.io/v1/ Labels: Experimental: false Insecure Registries: 127.0.0.0/8 Registry Mirrors: https://7if8cyiz.mirror.aliyuncs.com/ Live Restore Enabled: falseWARNING: No swap limit support