必读

  • Docker只能运行在64位系统上
  • Docker要求linux内核版本在3.1以上,即 CentOS 6.5 (64-bit) 或更高的版本,可以通过 uname -r 来来查看当前内核版本
  • Docker是PaaS提供商dotCloud开源的一个基于LXC的高级容器引擎,源代码托管在Github上,基于go语言并遵从Apache2.0协议开源

离线安装 docker 24.0.1

#.1.Confirm the os is centos 7.x
# cat /etc/redhat-release && uname -r
echo -e "\033[32m[Note] Apply for Centos 7.x, Ubuntu 20.x, Kylin v10.\033[0m"

#.2.Enable-ip-forward
sudo sed -i 's/^net.ipv4.ip_forward.*/net.ipv4.ip_forward=1/g' /etc/sysctl.conf
sudo cat /etc/sysctl.conf | grep "^net.ipv4.ip_forward" > /dev/null || echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
sudo /sbin/sysctl -p /etc/sysctl.conf

#.3.offline-setup-docker-ce
sudo curl -L http://iso.sqlfans.cn/docker/docker-24.0.1.tgz -o /opt/docker-24.0.1.tgz
sudo curl -s -L http://iso.sqlfans.cn/docker/docker.service -o /opt/docker.service
sudo tar -xvf /opt/docker-24.0.1.tgz --directory=/opt/
sudo mv /opt/docker/* /usr/bin/
sudo mv /opt/docker.service /etc/systemd/system/
sudo rm -rf /opt/docker
sudo chmod +x /etc/systemd/system/docker.service
sudo systemctl daemon-reload
sudo systemctl start docker
sudo systemctl is-active docker

#.4.set-on-start
sudo systemctl enable docker
sudo systemctl is-enabled docker
  • 清除上面的安装痕迹,可参考下面:
# systemctl stop docker
# systemctl disable docker.service
# rm -rf /opt/{docker,docker.service}
# rm -f /etc/systemd/system/docker.service
# rm -f  /usr/bin/{docker*,containerd*,ctr,runc}

离线安装 docker-compose 2.18.1

sudo curl -L "https://github.com/docker/compose/releases/download/v2.18.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/bin/docker-compose
sudo docker-compose --version
  • 若请求 github.com 速度太慢,可使用作者自己搭建的接口
sudo curl -L "http://iso.sqlfans.cn/docker/compose/v2.18.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/bin/docker-compose
sudo chmod +x /usr/bin/docker-compose
docker-compose --version

修改 docker 默认根目录

  • 若挂载点 /data 容量更大,则建议调整docker默认存放镜像/容器/数据卷的路径,由 /var/lib/docker 改为 /data/docker/lib,具体可参考下面:
sudo mkdir -p /data/docker/lib
sudo systemctl stop docker
sudo rsync -avz /var/lib/docker/ /data/docker/lib
sudo mv /var/lib/docker /var/lib/docker.delete
echo '{"data-root":"/data/docker/lib"}' > /etc/docker/daemon.json
sudo systemctl restart docker 
sudo docker info | grep Root
  #.执行 docker info 若返回 Docker Root Dir: /data/docker/lib 则表示docker根目录修改成功
Copyright © https://yan-jian.com 2023 all right reserved更新时间: 2023-12-07 10:05:15

results matching ""

    No results matching ""