ubuntu 24.04 使用美国源安装最新版的docker

0 阅读4分钟

需求: 1.使用美国源安装最新版的docker; 2.使用美国源安装最新版的docker compose。

环境: 1.服务器:1台美国CN2大带宽(弹性),IP通过curl cip.cn显示为香港 2.操作系统:Ubuntu 24.04 LTS 3.IP address: 154.201.92.72

一、更新系统并安装依赖 1.更新和安装 运行 root@client:#apt-get update root@client:#apt-get install -y ca-certificates curl gnupg lsb-release

校验 root@client:~#curl --version

显示 curl 8.5.0 (x86_64-pc-linux-gnu) libcurl/8.5.0 OpenSSL/3.0.13 zlib/1.3 brotli/1.1.0 zstd/1.5.5 libidn2/2.3.7 libpsl/0.21.2 (+libidn2/2.3.7) libssh/0.10.6/openssl/zlib nghttp2/1.59.0 librtmp/2.3 OpenLDAP/2.6.7 Release-Date: 2023-12-06, security patched: 8.5.0-2ubuntu10.11 Protocols: dict file ftp ftps gopher gophers http https imap imaps ldap ldaps mqtt pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp Features: alt-svc AsynchDNS brotli GSS-API HSTS HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM PSL SPNEGO SSL threadsafe TLS-SRP UnixSockets zstd

校验 root@client:~#gpg --version

显示 gpg (GnuPG) 2.4.4 libgcrypt 1.10.3 Copyright (C) 2024 g10 Code GmbH License GNU GPL-3.0-or-later gnu.org/licenses/gp… This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.

Home: /root/.gnupg Supported algorithms: Pubkey: RSA, ELG, DSA, ECDH, ECDSA, EDDSA Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH, CAMELLIA128, CAMELLIA192, CAMELLIA256 Hash: SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224 Compression: Uncompressed, ZIP, ZLIB, BZIP2 gpg (GnuPG) 2.4.4 libgcrypt 1.10.3 Copyright (C) 2024 g10 Code GmbH License GNU GPL-3.0-or-later gnu.org/licenses/gp… This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.

Home: /root/.gnupg Supported algorithms: Pubkey: RSA, ELG, DSA, ECDH, ECDSA, EDDSA Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH, CAMELLIA128, CAMELLIA192, CAMELLIA256 Hash: SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224 Compression: Uncompressed, ZIP, ZLIB, BZIP2

二、添加 Docker 官方 GPG 密钥 1.创建密钥目录 运行 root@client:~#install -m 0755 -d /etc/apt/keyrings

2.下载并解密 GPG 密钥 运行 root@client:~#curl -fsSL download.docker.com/linux/ubunt… | gpg --dearmor -o /etc/apt/keyrings/docker.gpg chmod a+r /etc/apt/keyrings/docker.gpg

校验 root@client:~#ls -l /etc/apt/keyrings/docker.gpg

显示 -rw-r--r-- 1 root root 2760 Jul 16 11:48 /etc/apt/keyrings/docker.gpg

三、添加 Docker 官方 APT 源 1.添加 运行 root@client:~#echo "deb [arch=(dpkgprintarchitecture)signedby=/etc/apt/keyrings/docker.gpg]https://download.docker.com/linux/ubuntu(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu (lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null

校验 root@client:~#cat /etc/apt/sources.list.d/docker.list

显示 deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] download.docker.com/linux/ubunt… noble stable

四、安装最新版 Docker Engine 和 Compose 插件 1.安装 运行 root@client:~#apt-get update apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

校验 root@client:~#docker --version

显示 Docker version 29.6.1, build 8900f1d

校验 root@client:~#docker compose version

显示 Docker Compose version v5.3.1

五、启动 Docker 并设置开机自启 1.启动和激活 运行 root@client:#systemctl start docker root@client:#systemctl enable docker

校验 root@client:~#systemctl status docker

显示 ● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; preset: enabled) Active: active (running) since Thu 2026-07-16 11:50:00 UTC; 20min ago TriggeredBy: ● docker.socket Docs: docs.docker.com Main PID: 8057 (dockerd) Tasks: 13 Memory: 33.1M (peak: 38.6M) CPU: 2.144s CGroup: /system.slice/docker.service └─8057 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Jul 16 11:50:00 client dockerd[8057]: time="2026-07-16T11:50:00.033755801Z" level=info msg="Initializing buildkit" Jul 16 11:50:00 client dockerd[8057]: time="2026-07-16T11:50:00.384412803Z" level=info msg="Completed buildkit initialization" Jul 16 11:50:00 client dockerd[8057]: time="2026-07-16T11:50:00.397443075Z" level=info msg="Daemon has completed initialization" Jul 16 11:50:00 client dockerd[8057]: time="2026-07-16T11:50:00.397841289Z" level=info msg="API listen on /run/docker.sock" Jul 16 11:50:00 client systemd[1]: Started docker.service - Docker Application Container Engine. Jul 16 11:51:06 client dockerd[8057]: time="2026-07-16T11:51:06.219734561Z" level=info msg="image pulled" digest="sha256:c3cbe1cc1aa588a64951ac6286e0df7b27fe2e6324b1001c619bb358770c0178" rem> Jul 16 11:51:06 client dockerd[8057]: time="2026-07-16T11:51:06.552487069Z" level=info msg="sbJoin: gwep4 ''->'2d48fb5d6800', gwep6 ''->''" eid=2d48fb5d6800 ep=hungry_jennings net=bridge nid> Jul 16 11:51:06 client dockerd[8057]: time="2026-07-16T11:51:06.636260899Z" level=info msg="received task-delete event from containerd" container=e910ac7768a2da2d493b3c95b2f16d27c0884329b603> Jul 16 11:52:00 client dockerd[8057]: time="2026-07-16T11:52:00.103394184Z" level=info msg="sbJoin: gwep4 ''->'cdebc6c06f63', gwep6 ''->''" eid=cdebc6c06f63 ep=compose-test-test-1 net=compos> Jul 16 11:52:00 client dockerd[8057]: time="2026-07-16T11:52:00.166023064Z" level=info msg="received task-delete event from containerd" container=21a14dd094684d74c532f0dc78167cff138e035a0484> lines 1-22/22 (END)