菜鸟操作
1、docker安装(基于ubuntn20.4-v)
- 1.1 更新 apt-get 源
sudo apt-get update
- 1.2 安装包允许 apt-get 通过 https 使用仓库
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
- 1.3 添加 docker 官方 GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
- 1.4 设置 docker 稳定版仓库
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
- 1.5 设置完毕仓库,重新更新源
sudo apt-get update
- 1.6 更新上面的源时,可能会出现如下错误(类似下边的错误)
获取:1 http://security.ubuntu.com/ubuntu focal-security InRelease [107 kB]
忽略:2 https://download.docker.com/linux/ubuntu focal InRelease
错误:3 https://download.docker.com/linux/ubuntu focal Release
404 Not Found [IP: 13.225.103.65 443]
命中:4 http://mirrors.163.com/ubuntu focal InRelease
命中:5 http://mirrors.163.com/ubuntu focal-updates InRelease
命中:6 http://mirrors.163.com/ubuntu focal-backports InRelease
忽略:7 http://dl.google.com/linux/chrome/deb stable InRelease
命中:8 http://dl.google.com/linux/chrome/deb stable Release
命中:9 http://archive.ubuntukylin.com:10006/ubuntukylin trusty InRelease
正在读取软件包列表... 完成
E: 仓库 “https://download.docker.com/linux/ubuntu focal Release” 没有 Release 文件。
N: 无法安全地用该源进行更新,所以默认禁用该源。
N: 参见 apt-secure(8) 手册以了解仓库创建和用户配置方面的细节。
- 1.7 处理方法
deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable
- 1.8 再次更新源
sudo apt-get update
- 1.9 可能会出现如下错误 (类似下边的错误)
获取:1 http://security.ubuntu.com/ubuntu focal-security InRelease [107 kB]
获取:2 https://download.docker.com/linux/ubuntu bionic InRelease [64.4 kB]
命中:3 http://mirrors.163.com/ubuntu focal InRelease
命中:4 http://mirrors.163.com/ubuntu focal-updates InRelease
命中:5 http://mirrors.163.com/ubuntu focal-backports InRelease
忽略:6 http://dl.google.com/linux/chrome/deb stable InRelease
命中:7 http://dl.google.com/linux/chrome/deb stable Release
命中:8 http://archive.ubuntukylin.com:10006/ubuntukylin trusty InRelease
忽略:10 https://download.docker.com/linux/ubuntu focal InRelease
获取:11 https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages [11.0 kB]
错误:12 https://download.docker.com/linux/ubuntu focal Release
404 Not Found [IP: 13.225.103.32 443]
正在读取软件包列表... 完成
E: 仓库 “https://download.docker.com/linux/ubuntu focal Release” 没有 Release 文件。
N: 无法安全地用该源进行更新,所以默认禁用该源。
N: 参见 apt-secure(8) 手册以了解仓库创建和用户配置方面的细节。
- 1.10 再次更新源
sudo apt-get update
- 1.11 安装最新的 docker-ce
sudo apt-get install docker-ce
- 1.12 避免每次使用 docker 命令都需要加上 sudo
sudo usermod -a -G docker $USER 或者 sudo usermod -aG docker $USER
- 1.13 启动并加入开机启动
systemctl start docker
systemctl enable docker
- 1.14 重启系统 reboot
2、docker安装(基于CentOS 系统3.10以上)
- 1、通过 uname -r 命令查看你当前的内核版本
uname -r
- 2、使用 root 权限登录 Centos。确保 yum 包更新到最新。
yum -y update
- 3、卸载旧版本(如果安装过旧版本的话)
yum remove docker docker-common docker-selinux docker-engine
- 4、安装需要的软件包, yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的
yum install -y yum-utils device-mapper-persistent-data lvm2
- 5、设置yum源
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
- 6、可以查看所有仓库中所有docker版本,并选择特定版本安装
yum list docker-ce --showduplicates | sort -r
- 7、安装docker
sudo yum install -y docker-ce #由于repo中默认只开启stable仓库,故这里安装的是最新稳定版18.03.1
- 8、启动并加入开机启动
systemctl start docker
systemctl enable docker
- 9、验证安装是否成功(有client和service两部分表示docker安装启动都成功了)
docker version
-
3、配置镜像加速器(ubuntn或者Centos)针对Docker客户端版本大于 1.10.0 的用户
(通过https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors 注册获取对应的系统类型 镜像加速地址)
您可以通过修改daemon配置文件/etc/docker/daemon.json来使用加速器
- 1 新建文件夹
sudo mkdir -p /etc/docker
- 2 直接执行下边的代码
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://ipcpgutr.mirror.aliyuncs.com"]
}
EOF
- 3 刷新(让json配置文件生效)
sudo systemctl daemon-reload
sudo systemctl restart docker
- 4、镜像相关命令
搜索镜像 # docker search java
下载镜像docker pull java:8
列出镜像使用 docker images命令即可列出已下载的镜像
删除镜像 使用 docker rmi IMAGE ID 命令即可删除指定镜像(IMAGE ID对应的镜像文件类似PID)
- 5、示例
启动容器 docker run -d -p 81:80 nginx
(回去镜像文件仓库查找有咩有nginx,有则启动,没有则下載后再启动:81端口,浏览器直接可以访问,80不可 注:防火墙必须关闭)
- 6、后续...
先删除容器,在删除镜像
查询容器 : docker ps –a
使用容器id删除容器: docker rm ID(为镜像ID)
查询镜像 : docker images
使用镜像id删除镜像 : docker rmi ID(为镜像ID)