Docker安装

查看Linux系统版本 发行版
# 查看linux系统内核版本
cat /proc/version
uname -a
# 查看linux系统发行版本
lsb_release -a

1.CentOS 7 安装docker

# 安装所需的软件包
sudo yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2

# 设置阿里云仓库
sudo yum-config-manager \
    --add-repo \
    http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

sudo yum install -y docker-ce docker-ce-cli containerd.io

systemctl start docker
systemctl enable docker

# 卸载
yum remove docker-ce
rm -rf /var/lib/docker

2.Ubuntu20.04安装Docker

# 卸载
sudo apt-get remove docker docker-engine docker.io containerd runc
# 依赖
sudo apt-get install apt-transport-https ca-certificates software-properties-common curl

# 官方源
sudo 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 $(lsb_release -cs) stable"
# 科大源
curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu 

# 安装
sudo apt update
sudo apt-get install docker-ce docker-ce-cli containerd.io
sudo systemctl start docker.service
sudo systemctl enable docker.service

# docker root权限问题
# 添加docker用户组
sudo grupadd docker
# 将登陆用户加入到docker用户组中
sudo gpasswd -a $USER docker
# 更新用户组
newgrp docker

# apt-get Unmet dependencies 包依赖损坏问题
# 按提示修复
sudo apt --fix-broken install
sudo apt-get update
sudo apt-get upgrade

3.Docker日志限制

# /etc/docker 目录,创建daemon.json文件,配置如下:
# 私仓
{
  "insecure-registries": ["192.168.1.204:5000"]
}
# 镜像加速
{
  "registry-mirrors": ["https://jn1i0xkr.mirror.aliyuncs.com"]
}
# 日志文件大小限制
{
  "log-driver":"json-file",
  "log-opts": {"max-size":"500m", "max-file":"3"}
}
# 配置GC,限制构建缓存
{
  "builder": {
    "gc": {
      "enabled": true,
      "defaultKeepStorage": "10GB",
      "policy": [
        { "keepStorage": "5GB", "filter": ["unused-for=2200h"] },
        { "keepStorage": "10GB", "filter": ["unused-for=3300h"] },
        { "keepStorage": "20GB", "all": true }
      ]
    }
  }
}

# 配置修改后重启
systemctl daemon-reload
systemctl restart docker
4.Amazon的服务器安装docker
# 安装步骤
sudo yum install -y amazon-linux-extras yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --enable extras
sudo amazon-linux-extras install docker
# 启动
sudo service docker start
# 停止
sudo service docker stop
# 查看状态
sudo service docker status
# 将 ec2-user 添加到 docker 组,以便您能够执行 Docker 命令,而无需使用 sudo
sudo usermod -a -G docker ec2-user
# 更新用户组,不能加sudo
newgrp docker 
# 自动启动
sudo systemctl enable docker.service
5.Ubuntu22
sudo apt-get update
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

sudo apt-get -y update
sudo apt-get -y install docker-ce
sudo systemctl start docker.service
sudo systemctl enable docker.service
6.docker-compose安装

版本页面:https://github.com/docker/compose/releases

# 命令下载
sudo curl -L "https://github.com/docker/compose/releases/download/v2.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

# 执行权限
sudo chmod +x /usr/local/bin/docker-compose

二、常用命令

1.无用镜像、存储清理
# 使用docker system df命令,在执行清除镜像之前先查看镜像和容器的数量。
docker system df
# 注:类似于Linux上的df命令,用于查看Docker的磁盘使用情况。这条命令可以查看到node节点中镜像和容器的数量

# 使用docker system prune –a清除无用的镜像
docker system prune -a
# 注:docker system prune命令可以用于清理磁盘,删除关闭的容器、无用的数据卷和网络,以及dangling镜像(即无tag的镜像)。
# docker system prune -a命令清理得更加彻底,可以将没有容器使用Docker镜像都删掉。

# 只清理images
docker images prune -f
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值