Manage docker remotely

本文最后更新于:2024年8月9日 晚上

Why I’m doing this?

I just want to have a docker environment and I don’t want installed it on my machine,sometime is too huge to install docker on workstation machines(install docker desktop on macOS will at latest 4GB Storage and take some memory). macOS don’t have docker cli service only have desktop which I don’t want to have a GUI.

At meanwhile I have docker installed on my remote server, I’m thinking what if we manage remote docker just like kubectl, the fact is this is workable. So let’s get started:

Remote Server

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# on remote docker host
>_ root ~ # mkdir /etc/systemd/system/docker.service.d
>_ root ~ # vim /etc/systemd/system/docker.service.d/docker.conf
>_ root ~ # cat /etc/systemd/system/docker.service.d/docker.conf
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd
# check listen port
>_ root ~ # grep ExecStart /usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock --selinux-enabled=false --log-opt max-size=1g
# make port keep same as service file
>_ root ~ # vim /etc/docker/daemon.json
>_ root ~ # cat /etc/docker/daemon.json
{
"hosts":[
"unix:///var/run/docker.sock",
"tcp://0.0.0.0:4243"
]
}
>_ root ~ # systemctl daemon-reload
>_ root ~ # systemctl restart docker

Client

1
2
3
4
5
6
7
8
9
10
11
12
# on macOS install docker command cli
~ » brew install docker
~ » docker -H bo.ms:4243 version
Client: Docker Engine - Community
Version: 20.10.22
API version: 1.41
...
~ » export DOCKER_HOST="tcp://bo.ms:4243"
~ » echo "export DOCKER_HOST="tcp://bo.ms:4243"" >> ~/.zshrc
~ » source ~/.zshrc
~ » docker ps | grep ldap
bc8ea256297e osixia/openldap "/container/tool/run" 7 days ago Up 13 minutes 0.0.0.0:389->389/tcp, :::389->389/tcp, 0.0.0.0:636->636/tcp, :::636->636/tcp ldap

This is just a test environment for test purpose, for production we have to configure TLS to make sure the communication between client and server is secure.

Here is an example of tutorial how how to configure it with ssl certificate.

https://juejin.cn/post/7120568388216160270


Manage docker remotely
https://git.msft.vip/2023/01/13-Manage-docker-remotely/
作者
Jas0n0ss
发布于
2023年1月14日
更新于
2024年8月9日
许可协议