install

docker安装教程

本篇文章介绍如何安装docker(包括大陆网络环境和正常国际网络环境安装docker,本教程以debian 12 为例)

Chinese | English

国际网络环境安装

Tip

由于国际网络互通不需要太多操作至于要按照教程执行命令行即可

1.docker环境安装更新包列表

更新你的包列表,以确保你有最新的包信息:

# --run--
sudo apt-get update

2.安装必要的依赖

安装一些必要的依赖项:

# --run--
sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release

3.添加 Docker 官方 GPG 密钥

添加 Docker 的官方 GPG 密钥:

# --run--
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

4.设置存储库

使用以下命令设置 Docker 存储库:

# --run--
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

5.更新包列表

再次更新包列表,以包含新的 Docker 存储库

# --run--
sudo apt-get update

6.安装 Docker 引擎

安装 Docker 引擎:

# --run--
sudo apt-get install docker-ce docker-ce-cli containerd.io

7. 验证 Docker 安装

安装完成后,你可以通过运行以下命令来验证 Docker 是否安装正确:

# --run--
sudo systemctl status docker

当你看到下面这个显示说明你已经安装成功了


● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; preset: enabled)
     Active: active (running) since Sat 2024-11-16 03:19:58 EST; 29min ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 1054919 (dockerd)
      Tasks: 10
     Memory: 29.5M
        CPU: 3.229s
     CGroup: /system.slice/docker.service
             └─1054919 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Nov 16 03:19:58 twlite5-20240919120748bb43a6 dockerd[1054919]: time="2024-11-16T03:19:58.699468347-05:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can be used to set a preferred IP address"
Nov 16 03:19:58 twlite5-20240919120748bb43a6 dockerd[1054919]: time="2024-11-16T03:19:58.794049205-05:00" level=info msg="Loading containers: done."
Nov 16 03:19:58 twlite5-20240919120748bb43a6 dockerd[1054919]: time="2024-11-16T03:19:58.822284173-05:00" level=warning msg="WARNING: bridge-nf-call-iptables is disabled"
Nov 16 03:19:58 twlite5-20240919120748bb43a6 dockerd[1054919]: time="2024-11-16T03:19:58.822716476-05:00" level=warning msg="WARNING: bridge-nf-call-ip6tables is disabled"
Nov 16 03:19:58 twlite5-20240919120748bb43a6 dockerd[1054919]: time="2024-11-16T03:19:58.823018439-05:00" level=info msg="Docker daemon" commit=41ca978 containerd-snapshotter=false storage-driver=overlay2 version=27.3.1
Nov 16 03:19:58 twlite5-20240919120748bb43a6 dockerd[1054919]: time="2024-11-16T03:19:58.823307535-05:00" level=info msg="Daemon has completed initialization"
Nov 16 03:19:58 twlite5-20240919120748bb43a6 dockerd[1054919]: time="2024-11-16T03:19:58.886036569-05:00" level=info msg="API listen on /run/docker.sock"
Nov 16 03:19:58 twlite5-20240919120748bb43a6 systemd[1]: Started docker.service - Docker Application Container Engine.
Nov 16 03:20:09 twlite5-20240919120748bb43a6 dockerd[1054919]: time="2024-11-16T03:20:09.820564557-05:00" level=warning msg="Error getting v2 registry: Get \"https://harbor.wapyyds.online/v2/\": remote error: tls: unrecognized name" spanID=1771640d81abd297 traceID=19763d526fa6cb12b9f389923d20cdd2
Nov 16 03:20:09 twlite5-20240919120748bb43a6 dockerd[1054919]: time="2024-11-16T03:20:09.821482112-05:00" level=info msg="Attempting next endpoint for pull after error: Get \"https://harbor.wapyyds.online/v2/\": remote error: tls: unrecognized name" spanID=1771640d81abd297 traceID=19763d526fa6cb12b9f389923d20cdd2

或者检查docker版本:

# --run--
docker -v

正常会显示docker版本:

root@twlite5-20240919120748bb43a6:~# docker -v
Docker version 27.3.1, build ce12230
root@twlite5-20240919120748bb43a6:~# 

国内网络环境安装

Warning

由于国内把docker环境给墙了,大多国内镜像库全部失效我尝试许多
方法发现效果都不怎么样,所以这里只提供三种安装思路。

1.科学上网(仅供学习交流,无其他引导)

Important

假如你家网络是软路由做网络终端,那将没任何问题,如果你只想给本地的linuxs设备上代理可以了解一下shellcrash

本地上代理,即科学上网实现国际网络环境(自己百度),再按照上面的教程来一遍。

2.本地离线安装

假如你本地局域网已经有了clash/v2ray代理,这些客户端都会有本地代理如http,socks。我们可以借助本地socks代理下载docker安装文件

docker下载地址:https://download.docker.com/linux/static/stable/ amd64就是x86,下面我将以docker-23.0.0.tgz版本为例在debian 12离线安装docker

1.代理下载安装文件:docker,docker-compose

首先本地我本地电脑支持本地socks代理:192.168.124.15:10808(无socks验证)

使用curl命令下载文件命令(无验证):

# --run--
curl --socks5-hostname 127.0.0.1:1080 -O http://example.com/file.zip

使用curl命令下载文件命令(有验证):

# --run--
curl --socks5-hostname 127.0.0.1:1080 --proxy-user username:password -O http://example.com/file.zip

由于我本地代理无验证,下载载地址为:https://download.docker.com/linux/static/stable/x86_64/docker-23.0.0.tgz,所以下载命令为:

# --run--
curl --socks5-hostname 192.168.124.15:10808  -O  https://download.docker.com/linux/static/stable/x86_64/docker-23.0.0.tgz

如果操作无误终端会显示:

root@localhost:~# curl --socks5-hostname 192.168.124.15:10808  -O  https://download.docker.com/linux/static/stable/x86_64/docker-23.0.0.tgz
 % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                Dload  Upload   Total   Spent    Left  Speed
100 71.8M  100 71.8M    0     0  6912k      0  0:00:10  0:00:10 --:--:-- 8741k
root@localhost:~# ls
docker-23.0.0.tgz

同理下载docker-composehttps://github.com/docker/compose/releases/download/v2.30.3/docker-compose-linux-x86_64

# --run--
curl --socks5-hostname 192.168.124.15:10808 -LO https://github.com/docker/compose/releases/download/v2.30.3/docker-compose-linux-x86_64
  • -L 选项让curl跟随重定向。
  • -O 选项用于将下载的文件保存为原始文件名。

2.离线安装docker:

  • 上传安装包

Tip

usr/bin是环境变量目录,在路径下可以直接运行docker命令

# 复制docker-23.0.0.tgz到 /usr/bin下
 # 解压
tar xvf docker-23.0.0.tgz
# ls -l docker
cp docker/* /usr/bin
# rm -rf docker docker-23.0.0.tgz

这一步如果没问题则你会看到:

root@localhost:~# ls
docker-23.0.0.tgz  docker-compose-linux-x86_64
root@localhost:~# tar xvf docker-23.0.0.tgz
docker/
docker/docker-proxy
docker/containerd
docker/dockerd
docker/runc
docker/docker-init
docker/containerd-shim-runc-v2
docker/ctr
docker/docker
root@localhost:~# ls -l docker
total 179192
-rwxr-xr-x 1 wap wap 38203392 Feb  2  2023 containerd
-rwxr-xr-x 1 wap wap  9752576 Feb  2  2023 containerd-shim-runc-v2
-rwxr-xr-x 1 wap wap 19152896 Feb  2  2023 ctr
-rwxr-xr-x 1 wap wap 34498624 Feb  2  2023 docker
-rwxr-xr-x 1 wap wap   765808 Feb  2  2023 docker-init
-rwxr-xr-x 1 wap wap  1945195 Feb  2  2023 docker-proxy
-rwxr-xr-x 1 wap wap 64941936 Feb  2  2023 dockerd
-rwxr-xr-x 1 wap wap 14214368 Feb  2  2023 runc
root@localhost:~# cp docker/* /usr/bin
root@localhost:~# rm -rf docker docker-23.0.0.tgz
root@localhost:~# ls
docker-compose-linux-x86_64
  • 配置docker服务
# vim /etc/systemd/system/docker.service
# 添加
[Unit]

Description=Docker Application Container Engine

Documentation=https://docs.docker.com

After=network-online.target firewalld.service

Wants=network-online.target


[Service]

Type=notify

ExecStart=/usr/bin/dockerd

ExecReload=/bin/kill -s HUP $MAINPID

LimitNOFILE=infinity

LimitNPROC=infinity

TimeoutStartSec=0

Delegate=yes

KillMode=process

Restart=on-failure

StartLimitBurst=3

StartLimitInterval=60s


[Install]

WantedBy=multi-user.target
  • 赋执行权限
chmod +x /etc/systemd/system/docker.service
systemctl daemon-reload
  • docker命令
# 开机启动
systemctl enable docker.service
# 启动docker
systemctl start docker
# docker状态
systemctl status docker
# 重启docker服务
systemctl restart docker

如果安装成功你会看到:

root@wap:~# service docker status
● docker.service - Docker Application Container Engine
     Loaded: loaded (/etc/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2024-11-16 11:57:46 UTC; 5min ago
       Docs: https://docs.docker.com
   Main PID: 15208 (dockerd)
      Tasks: 18 (limit: 4520)
     Memory: 77.4M
        CPU: 3.125s
     CGroup: /system.slice/docker.service
             ├─15208 /usr/bin/dockerd
             └─15215 containerd --config /var/run/docker/containerd/containerd.toml --log-level info

Nov 16 11:57:46 wap dockerd[15208]: time="2024-11-16T11:57:46.160374572Z" level=info msg="[core] [Channel #7 SubChanne>
Nov 16 11:57:46 wap dockerd[15208]: time="2024-11-16T11:57:46.160389038Z" level=info msg="[core] [Channel #7] Channel >
Nov 16 11:57:46 wap dockerd[15208]: time="2024-11-16T11:57:46.204536094Z" level=info msg="Loading containers: start."
Nov 16 11:57:46 wap dockerd[15208]: time="2024-11-16T11:57:46.416486809Z" level=info msg="Default bridge (docker0) is >
Nov 16 11:57:46 wap dockerd[15208]: time="2024-11-16T11:57:46.542318404Z" level=info msg="Loading containers: done."
Nov 16 11:57:46 wap dockerd[15208]: time="2024-11-16T11:57:46.556297097Z" level=info msg="Docker daemon" commit=d7573a>
Nov 16 11:57:46 wap dockerd[15208]: time="2024-11-16T11:57:46.556544908Z" level=info msg="Daemon has completed initial>
Nov 16 11:57:46 wap dockerd[15208]: time="2024-11-16T11:57:46.577570543Z" level=info msg="[core] [Server #10] Server c>
Nov 16 11:57:46 wap systemd[1]: Started Docker Application Container Engine.
Nov 16 11:57:46 wap dockerd[15208]: time="2024-11-16T11:57:46.581761071Z" level=info msg="API listen on /var/run/docke>
lines 1-22/22 (END)

3.1panel面板安装

安装命令:

# --run--
curl -sSL https://resource.fit2cloud.com/1panel/package/quick_start.sh -o quick_start.sh && bash quick_start.sh

安装完之后,你可以选择保留,也可以选择卸载,但是docker是完完整整的安装成功了!

我的个人网站 仔仔引导页, 当然还有我的个人blog ZZのBlog.

赞助:Img