When we install Docker and run it, the remote access is disabled in the default configuration.
Sometimes we need the remote access. Actually the Docker official provides how to enable it for us but it’s useless for me because I can not modify&save the docker.service file when I follow the tutorial.
If you have interests, please see: Configure remote access for Docker daemon

So this is why I write this short post to record a solution to enable the remote access, in case I forget it in the future.
PS. I still find the solution on the Internet.

step 1

We need to change the docker.service file on the /lib/systemd/system/:
sudo vim /lib/systemd/system/docker.service
Find the [Service] title and append -H=tcp://0.0.0.0:2375 in the ExecStart
Save it, and the finnal file may like this:

cat /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
Wants=network-online.target
Requires=docker.socket containerd.service

[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:// -H=tcp://0.0.0.0:2375 --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=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

# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity

# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity

# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes

# kill only the docker process, not all processes in the cgroup
KillMode=process
OOMScoreAdjust=-500

[Install]
WantedBy=multi-user.target

step 2

Then we need to reboot the Docker server:
sudo systemctl daemon-reload
sudo service docker restart

step 3

Checking the remote access by following commands:
sudo netstat -lntp | grep dockerd to check the ip and port whether enabled on the server.
Or:
On client, use curl http://{{server_ip}}:2375/images/json, the result may like this(including all the images you have pulled before.):

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
[
    {
        "Containers":-1,
        "Created":1632440877,
        "Id":"sha256:feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412",
        "Labels":null,
        "ParentId":"",
        "RepoDigests":[
            "hello-world@sha256:aa0cc8055b82dc2509bed2e19b275c8f463506616377219d9642221ab53cf9fe"
        ],
        "RepoTags":[
            "hello-world:latest"
        ],
        "SharedSize":-1,
        "Size":13256,
        "VirtualSize":13256
    }
]