背景 由於我個人電腦是2020款m1,16G,256G。一方面,平時除了運行多個瀏覽器,還有coding 編輯器等等,記憶體確實很緊張。其次呢,m1 是ARM的架構,所以構建的鏡像是無法在X86的機器上運行的。所以我嘗試將docker引擎和client分開。 第一步:下載二進位docker 客戶端文件 ...
背景
由於我個人電腦是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
vim /usr/lib/systemd/system/docker.service
···
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target docker.socket firewalld.service containerd.service time-set.target
Wants=network-online.target containerd.service
Requires=docker.socket
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
# ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
### 註意這裡,我複製了一行
ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375 --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutStartSec=0
RestartSec=2
Restart=always
# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3
# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s
···
第三步:解壓並添加環境變數
解壓文件後如下:
添加環境變數
註意:
使用$PATH
命令查看環境變數
# 查看環境變數
$PATH
/Users/lanjx/opt/anaconda3/bin:/Users/lanjx/.nvm/versions/node/v16.18.0/bin:....太長了,忽略
# 將圖中文件解壓到環境變數對應的目錄中
sudo cp DownLoads/docker/docker /usr/local/sbin/
sudo chmod +x /usr/local/sbin/docker
# 添加環境變數
vim .zshrc
# 將下麵一句添加到文件末尾
...
export DOCKER_HOST=tcp://192.168.0.1:2375
修改文件
vim ~/.docker/config.json
{
"auths": {
"docker.cnblogs.com": {}
},
"credsStore": "desktop",
"currentContext": "default",
// 添加了下麵這一行
"hosts": ["tcp://192.168.0.1:2375"]
}
第四步:測試
到這裡基本上已經差不多了,剩下的就是補全剩餘的組件即可
docker info
Client:
Version: 24.0.7
Context: default
Debug Mode: false
Plugins:
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
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
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
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
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
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
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
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
Server:
Containers: 2
Running: 0
Paused: 0
Stopped: 2
Images: 0
Server Version: 24.0.6
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Using metacopy: false
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 61f9fd88f79f081d64d6fa3bb1a0dc71ec870523
runc version: v1.1.9-0-gccaecfc
init version: de40ad0
Security Options:
seccomp
Profile: builtin
Kernel Version: 3.10.0-1160.80.1.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 8
Total Memory: 15.49GiB
Name: localhost.localdomain
ID: 1e789c39-61f4-4269-8616-47944d1865cb
Docker Root Dir: /data/docker
Debug Mode: false
Experimental: false
Insecure Registries:
127.0.0.0/8
Registry Mirrors:
https://registry.docker-cn.com/
https://docker.mirrors.ustc.edu.cn/
Live Restore Enabled: false
WARNING: API is accessible on http://0.0.0.0:2375 without encryption.
Access to the remote API is equivalent to root access on the host. Refer
to the 'Docker daemon attack surface' section in the documentation for
more information: https://docs.docker.com/go/attack-surface/
第五步:補全插件
方法一:
可以去github上挨個下載(這樣太麻煩了,可能還上不去這個網站):傳送門
方法二:
下載桌面版,解壓開複製裡面的文件
這種方法簡單粗暴,補全後刪除即可
下載鏈接:傳送門,下載完成後,如下圖:
雙擊打開後,訪達中會有這樣一個東西。
然後右擊Docker.app,選擇顯示包內容,接著複製如下目錄的文件到/Users/lanjx/.docker/cli-plugins
(註意用戶名,根據自己的實際路徑來)
接下來給許可權
sudo chmod +x /Users/lanjx/.docker/cli-plugins/*
到這裡就結束啦,重啟終端,看看效果~