翼度科技»论坛 云主机 LINUX 查看内容

docker 分离engine和client

5

主题

5

帖子

15

积分

新手上路

Rank: 1

积分
15
背景

由于我个人电脑是2020款m1,16G,256G。一方面,平时除了运行多个浏览器,还有coding 编辑器等等,内存确实很紧张。其次呢,m1 是ARM的架构,所以构建的镜像是无法在X86的机器上运行的。所以我尝试将docker引擎和client分开。
第一步:下载二进制docker 客户端文件

二进制client下载链接:传送门
如果是苹果选择aarch64,进去后选择版本(我选择的是最新版本)

第二步:安装docker

注意:
1、除了要安装docker以外,还需要开启api端口,因为客户端需要和服务端通过远程端口进行通信
2、个人安装的最新版本
3、注意开启2375端口,确保能telnet通
docker安装文档:传送门
配置远程端口:
Docker 启动文件添加-H tcp://0.0.0.0:2375
  1. vim /usr/lib/systemd/system/docker.service
复制代码
  1. ···
  2. [Unit]
  3. Description=Docker Application Container Engine
  4. Documentation=https://docs.docker.com
  5. After=network-online.target docker.socket firewalld.service containerd.service time-set.target
  6. Wants=network-online.target containerd.service
  7. Requires=docker.socket
  8. [Service]
  9. Type=notify
  10. # the default is not to use systemd for cgroups because the delegate issues still
  11. # exists and systemd currently does not support the cgroup feature set required
  12. # for containers run by docker
  13. # ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
  14. ### 注意这里,我复制了一行
  15. ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375 --containerd=/run/containerd/containerd.sock
  16. ExecReload=/bin/kill -s HUP $MAINPID
  17. TimeoutStartSec=0
  18. RestartSec=2
  19. Restart=always
  20. # Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
  21. # Both the old, and new location are accepted by systemd 229 and up, so using the old location
  22. # to make them work for either version of systemd.
  23. StartLimitBurst=3
  24. # Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
  25. # Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
  26. # this option work for either version of systemd.
  27. StartLimitInterval=60s
  28. ···
复制代码
第三步:解压并添加环境变量

解压文件后如下:


添加环境变量

注意:
使用$PATH 命令查看环境变量
  1. # 查看环境变量
  2. $PATH
复制代码
  1. /Users/lanjx/opt/anaconda3/bin:/Users/lanjx/.nvm/versions/node/v16.18.0/bin:....太长了,忽略
复制代码
  1. # 将图中文件解压到环境变量对应的目录中
  2. sudo cp DownLoads/docker/docker /usr/local/sbin/
  3. sudo chmod +x /usr/local/sbin/docker
复制代码
  1. # 添加环境变量
  2. vim .zshrc
复制代码
  1. # 将下面一句添加到文件末尾
  2. ...
  3. export DOCKER_HOST=tcp://192.168.0.1:2375
复制代码
修改文件
  1. vim ~/.docker/config.json
复制代码
  1. {
  2.         "auths": {               
  3.                  "docker.cnblogs.com": {}
  4.         },
  5.         "credsStore": "desktop",        
  6.         "currentContext": "default",
  7.                           // 添加了下面这一行
  8.         "hosts": ["tcp://192.168.0.1:2375"]
  9. }
复制代码
第四步:测试

到这里基本上已经差不多了,剩下的就是补全剩余的组件即可
  1. docker info
复制代码
  1. Client:
  2. Version:    24.0.7
  3. Context:    default
  4. Debug Mode: false
  5. Plugins:
  6. WARNING: Plugin "/Users/lanjx/.docker/cli-plugins/docker-buildx" is not valid: failed to fetch metadata: fork/exec /Users/lanjx/.docker/cli-plugins/docker-buildx: no such file or directory
  7. WARNING: Plugin "/Users/lanjx/.docker/cli-plugins/docker-compose" is not valid: failed to fetch metadata: fork/exec /Users/lanjx/.docker/cli-plugins/docker-compose: no such file or directory
  8. WARNING: Plugin "/Users/lanjx/.docker/cli-plugins/docker-dev" is not valid: failed to fetch metadata: fork/exec /Users/lanjx/.docker/cli-plugins/docker-dev: no such file or directory
  9. WARNING: Plugin "/Users/lanjx/.docker/cli-plugins/docker-extension" is not valid: failed to fetch metadata: fork/exec /Users/lanjx/.docker/cli-plugins/docker-extension: no such file or directory
  10. WARNING: Plugin "/Users/lanjx/.docker/cli-plugins/docker-init" is not valid: failed to fetch metadata: fork/exec /Users/lanjx/.docker/cli-plugins/docker-init: no such file or directory
  11. WARNING: Plugin "/Users/lanjx/.docker/cli-plugins/docker-sbom" is not valid: failed to fetch metadata: fork/exec /Users/lanjx/.docker/cli-plugins/docker-sbom: no such file or directory
  12. WARNING: Plugin "/Users/lanjx/.docker/cli-plugins/docker-scan" is not valid: failed to fetch metadata: fork/exec /Users/lanjx/.docker/cli-plugins/docker-scan: no such file or directory
  13. WARNING: Plugin "/Users/lanjx/.docker/cli-plugins/docker-scout" is not valid: failed to fetch metadata: fork/exec /Users/lanjx/.docker/cli-plugins/docker-scout: no such file or directory
  14. Server:
  15. Containers: 2
  16.   Running: 0
  17.   Paused: 0
  18.   Stopped: 2
  19. Images: 0
  20. Server Version: 24.0.6
  21. Storage Driver: overlay2
  22.   Backing Filesystem: extfs
  23.   Supports d_type: true
  24.   Using metacopy: false
  25.   Native Overlay Diff: true
  26.   userxattr: false
  27. Logging Driver: json-file
  28. Cgroup Driver: cgroupfs
  29. Cgroup Version: 1
  30. Plugins:
  31.   Volume: local
  32.   Network: bridge host ipvlan macvlan null overlay
  33.   Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
  34. Swarm: inactive
  35. Runtimes: io.containerd.runc.v2 runc
  36. Default Runtime: runc
  37. Init Binary: docker-init
  38. containerd version: 61f9fd88f79f081d64d6fa3bb1a0dc71ec870523
  39. runc version: v1.1.9-0-gccaecfc
  40. init version: de40ad0
  41. Security Options:
  42.   seccomp
  43.    Profile: builtin
  44. Kernel Version: 3.10.0-1160.80.1.el7.x86_64
  45. Operating System: CentOS Linux 7 (Core)
  46. OSType: linux
  47. Architecture: x86_64
  48. CPUs: 8
  49. Total Memory: 15.49GiB
  50. Name: localhost.localdomain
  51. ID: 1e789c39-61f4-4269-8616-47944d1865cb
  52. Docker Root Dir: /data/docker
  53. Debug Mode: false
  54. Experimental: false
  55. Insecure Registries:
  56.   127.0.0.0/8
  57. Registry Mirrors:
  58.   https://registry.docker-cn.com/
  59.   https://docker.mirrors.ustc.edu.cn/
  60. Live Restore Enabled: false
  61. WARNING: API is accessible on http://0.0.0.0:2375 without encryption.
  62.          Access to the remote API is equivalent to root access on the host. Refer
  63.          to the 'Docker daemon attack surface' section in the documentation for
  64.          more information: https://docs.docker.com/go/attack-surface/
复制代码
第五步:补全插件

方法一:

可以去github上挨个下载(这样太麻烦了,可能还上不去这个网站):传送门
方法二:

下载桌面版,解压开复制里面的文件
这种方法简单粗暴,补全后删除即可
下载链接:传送门,下载完成后,如下图:

双击打开后,访达中会有这样一个东西。

然后右击Docker.app,选择显示包内容,接着复制如下目录的文件到/Users/lanjx/.docker/cli-plugins(注意用户名,根据自己的实际路径来)


接下来给权限
  1. sudo chmod +x /Users/lanjx/.docker/cli-plugins/*
复制代码
到这里就结束啦,重启终端,看看效果~


来源:https://www.cnblogs.com/lanheader/p/17798929.html
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x

举报 回复 使用道具