1、Docker CE安装
参考:https://www.cnblogs.com/a120608yby/p/9883175.html
2、修改docker配置文件(这里以docker 24.0.7版本为例)
# 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 -H tcp://0.0.0.0:2375 #修改第13行 ExecReload=/bin/kill -s HUP $MAINPID TimeoutStartSec=0 RestartSec=2 Restart=always ...
3、重启服务
systemctl daemon-reload systemctl restart docker
4、配置命令自动补全
dnf install bash-completion -y
5、测试
# 查看版本 # curl http://localhost:2375/version {"Platform":{"Name":"Docker Engine - Community"},"Components":[{"Name":"Engine","Version":"24.0.7","Details":{"ApiVersion":"1.43","Arch":"amd64","BuildTime":"2023-10-26T09:07:45.000000000+00:00","Experimental":"false","GitCommit":"311b9ff","GoVersion":"go1.20.10","KernelVersion":"5.14.0-362.13.1.el9_3.x86_64","MinAPIVersion":"1.12","Os":"linux"}},{"Name":"containerd","Version":"1.6.26","Details":{"GitCommit":"3dd1e886e55dd695541fdcd67420c2888645a495"}},{"Name":"runc","Version":"1.1.10","Details":{"GitCommit":"v1.1.10-0-g18a0cb0"}},{"Name":"docker-init","Version":"0.19.0","Details":{"GitCommit":"de40ad0"}}],"Version":"24.0.7","ApiVersion":"1.43","MinAPIVersion":"1.12","GitCommit":"311b9ff","GoVersion":"go1.20.10","Os":"linux","Arch":"amd64","KernelVersion":"5.14.0-362.13.1.el9_3.x86_64","BuildTime":"2023-10-26T09:07:45.000000000+00:00"} # 从其他主机连接测试 # docker -H tcp://10.32.161.126:2375 images REPOSITORY TAG IMAGE ID CREATED SIZE goharbor/harbor-exporter v2.10.0 1d3fdd3d102d 2 weeks ago 106MB goharbor/redis-photon v2.10.0 5083850c5206 2 weeks ago 165MB goharbor/trivy-adapter-photon v2.10.0 5873942a56be 2 weeks ago 478MB goharbor/harbor-registryctl v2.10.0 7a3b7d7d972c 2 weeks ago 149MB goharbor/registry-photon v2.10.0 9baecb934ded 2 weeks ago 83.4MB goharbor/nginx-photon v2.10.0 d1010aed334c 2 weeks ago 154MB goharbor/harbor-log v2.10.0 518f000ddf00 2 weeks ago 164MB goharbor/harbor-jobservice v2.10.0 4960b98063d3 2 weeks ago 140MB goharbor/harbor-core v2.10.0 00c9a2f5729c 2 weeks ago 168MB goharbor/harbor-portal v2.10.0 f3d83a4e7733 2 weeks ago 163MB goharbor/harbor-db v2.10.0 8215768668f6 2 weeks ago 269MB goharbor/prepare v2.10.0 2ac2fd8f7595 2 weeks ago 208MB nginx stable-alpine 0cd127114627 8 months ago 41.1MB
6、远程连接管理
# 定义环境变量方式 export DOCKER_HOST=tcp://10.32.161.126:2375 # 配置docker上下文方式 docker context create docker-126 --docker host=tcp://10.32.161.126:2375 docker context create docker-125 --docker host=tcp://10.32.161.125:2375 # 查看docker上下文 # docker context ls NAME DESCRIPTION DOCKER ENDPOINT ERROR default * Current DOCKER_HOST based configuration unix:///var/run/docker.sock docker-125 tcp://10.32.161.125:2375 docker-126 tcp://10.32.161.126:2375 # 使用docker上下文 # docker context use docker-126 docker-126 Current context is now "docker-126" # docker images REPOSITORY TAG IMAGE ID CREATED SIZE goharbor/harbor-exporter v2.10.0 1d3fdd3d102d 2 weeks ago 106MB goharbor/redis-photon v2.10.0 5083850c5206 2 weeks ago 165MB goharbor/trivy-adapter-photon v2.10.0 5873942a56be 2 weeks ago 478MB goharbor/harbor-registryctl v2.10.0 7a3b7d7d972c 2 weeks ago 149MB goharbor/registry-photon v2.10.0 9baecb934ded 2 weeks ago 83.4MB goharbor/nginx-photon v2.10.0 d1010aed334c 2 weeks ago 154MB goharbor/harbor-log v2.10.0 518f000ddf00 2 weeks ago 164MB goharbor/harbor-jobservice v2.10.0 4960b98063d3 2 weeks ago 140MB goharbor/harbor-core v2.10.0 00c9a2f5729c 2 weeks ago 168MB goharbor/harbor-portal v2.10.0 f3d83a4e7733 2 weeks ago 163MB goharbor/harbor-db v2.10.0 8215768668f6 2 weeks ago 269MB goharbor/prepare v2.10.0 2ac2fd8f7595 2 weeks ago 208MB nginx stable-alpine 0cd127114627 8 months ago 41.1MB # docker context use docker-125 docker-125 Current context is now "docker-125" # docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx stable-alpine 0cd127114627 8 months ago 41.1MB
参考:https://docs.docker.com/engine/reference/commandline/dockerd/