ubuntu下载docker依赖包

发布于:2024-08-02 ⋅ 阅读:(100) ⋅ 点赞:(0)

Ubuntu下载docker依赖包

​ 公司对外客户一直偏向对安全性要求较高,因此在外部署服务得时候,安装docker是一件极为重要得事情,之前得服务器得系统是centos7。在上一家公司的时候,已经把docker所需得rpm包已经集成打包好了。并且docker的24版本以后,docker核心已经有compose了。但是现在的客户方都安装的是基于ubuntu的系统。今天实现deb包的下载和脚本的自动化安装。

导入docker的源

说明:ubuntu没有docker的下载源,可以先去阿里源把docker的源下载下来

# step 1: 安装必要的一些系统工具
sudo apt-get update
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
# step 2: 安装GPG证书
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
# Step 3: 写入软件源信息
sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
# Step 4: 更新并安装Docker-CE
sudo apt-get -y update

参考URL docker源

创建docker文件夹并下载deb包

mkdir docker
cd docker
apt-get download $(apt-cache depends --recurse --no-recommends --no-suggests --no-conflicts  --no-breaks --no-replaces --no-enhances --no-pre-depends docker-ce |grep -v i386|grep  -v "^ ")


root@235:~/docker# ls
containerd.io_1.7.19-1_amd64.deb                         libc6_2.31-0ubuntu9.16_amd64.deb           libmnl0_1.0.4-2_amd64.deb                     libsystemd0_245.4-4ubuntu3.23_amd64.deb
docker-ce_5%3a27.1.1-1~ubuntu.20.04~focal_amd64.deb      libcrypt1_1%3a4.4.10-10ubuntu4_amd64.deb   libnetfilter-conntrack3_1.0.7-2_amd64.deb     libxtables12_1.8.4-3ubuntu2.1_amd64.deb
docker-ce-cli_5%3a27.1.1-1~ubuntu.20.04~focal_amd64.deb  libgcc-s1_10.5.0-1ubuntu1~20.04_amd64.deb  libnfnetlink0_1.0.1-3build1_amd64.deb         netbase_6.1_all.deb
gcc-10-base_10.5.0-1ubuntu1~20.04_amd64.deb              libip4tc2_1.8.4-3ubuntu2.1_amd64.deb       libnftnl11_1.1.5-1_amd64.deb
iptables_1.8.4-3ubuntu2.1_amd64.deb                      libip6tc2_1.8.4-3ubuntu2.1_amd64.deb       libseccomp2_2.5.1-1ubuntu1~20.04.2_amd64.deb

说明:一点要grep -v i386 ,前面下载了几次没有grep -v i386 ,一直在报没有i386的包。所以我选择通过grep -v 不下载i389,并且测试对docker的使用没有太大的影响。

安装

sudo dpkg -i *.deb

脚本化安装

#!/bin/bash
mkdir -p /etc/docker/

cat << 'EOF' > /etc/docker/daemon.json
{
  "log-driver": "json-file",
  "data-root": "/data/docker",
  "log-opts": {
    "max-size": "100m",
    "max-file": "3"
  },
  "exec-opts": ["native.cgroupdriver=systemd"],
  "storage-driver": "overlay2",
  "insecure-registries": [
    "192.168.35.235:80"
  ],
  "registry-mirrors": [
    "https://docker.mirrors.ustc.edu.cn",
    "https://hub-mirror.c.163.com"
  ]
}
EOF
cat << 'EOF' >> /etc/sysctl.conf
	net.bridge.bridge-nf-call-iptables = 1
	net.ipv4.ip_forward = 1
	net.bridge.bridge-nf-call-ip6tables = 1
EOF
sysctl --system

sudo dpkg -i *.deb
systemctl enable docker ; systemctl start docker
cat << 'EOF' > /usr/bin/docker-compose
#!/bin/bash
docker compose $@
EOF
chmod +x /usr/bin/docker-compose
docker-compose version

百度网盘docker依赖的分享:

docker_deb包完整资源