Docker容器

快速安装脚本并设置Hub源

bash <(curl -sSL https://linuxmirrors.cn/docker.sh)

其他安装方式

sudo bash -c "curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh"

官网安装

sudo apt update
sudo apt upgrade -y
sudo apt install curl vim wget gnupg dpkg apt-transport-https lsb-release ca-certificates
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

加入 Docker 的 GPG 公钥和 apt 源 (非必要)
Debian

curl -sSL https://download.docker.com/linux/debian/gpg | gpg --dearmor > /usr/share/keyrings/docker-ce.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-ce.gpg] https://download.docker.com/linux/debian $(lsb_release -sc) stable" > /etc/apt/sources.list.d/docker.list

国内

curl -sS https://download.docker.com/linux/debian/gpg | gpg --dearmor > /usr/share/keyrings/docker-ce.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-ce.gpg] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/debian $(lsb_release -sc) stable" > /etc/apt/sources.list.d/docker.list

如果需要某个特定用户可以用 Docker rootless 模式运行 Docker,那么可以把这个用户也加入 docker 组,比如我们把 www-data 用户加进去:

apt install docker-ce-rootless-extras
sudo usermod -aG docker www-data

兼容老的 docker-compose

curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-Linux-x86_64 > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

修改配置并重启

cat > /etc/docker/daemon.json << EOF
{
    "registry-mirrors": ["https://docker.1ms.run","https://dockerproxy.net","https://docker.m.daocloud.io"],
    "log-driver": "json-file",
    "log-opts": {
        "max-size": "20m",
        "max-file": "3"
    },
    "ipv6": true,
    "fixed-cidr-v6": "fd00:dead:beef:c0::/80",
    "experimental":true,
    "ip6tables":true
}
EOF
systemctl restart docker

# docker info 报错
sudo modprobe br_netfilter
sudo sysctl net.bridge.bridge-nf-call-iptables=1
sudo sysctl net.bridge.bridge-nf-call-ip6tables=1
sudo sysctl -p

配置会增加一段自定义内网 IPv6 地址,开启容器的 IPv6 功能,以及限制日志文件大小,防止 Docker 日志塞满硬盘

标签: Docker, Debian, Linux

添加新评论