Centos Docker1.12 configuration method for remote Rest api access

  • 2020-06-01 11:27:10
  • OfStack

By default, Docker does not have HTTP remote access enabled. By default, docker daemon is only supported through unix socket communication, and the configuration needs to be modified to use HTTP restful interface.

1, modify the configuration file, the file location/lib/systemd/system/docker service. Change the original ExecStart to:


[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network.target
[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
#ExecStart=/usr/bin/dockerd -H 192.168.25.130:2375
ExecStart=/usr/bin/docker daemon --tls=false -H unix:///var/run/docker.sock -H tcp://192.168.25.130:2375
ExecReload=/bin/kill -s HUP $MAINPID
# 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
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# 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
[Install]
WantedBy=multi-user.target

2. Perform


systemctl daemon-reload
systemctl restart docker.service

Note: if the docker command is not available, configure it in etc/profile:


export DOCKER_HOST= 'http://192.168.25.128:2375'

Is the effect of


source /etc/profile

3. Official API documentation

Official link: Docker Remote API v1.24


Related articles: