Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jrichardsz/84fdbd07910bae61df5b01662f3f48e1 to your computer and use it in GitHub Desktop.
Save jrichardsz/84fdbd07910bae61df5b01662f3f48e1 to your computer and use it in GitHub Desktop.
docker snippets dockerd dockerapi
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target 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:// --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

http://www.littlebigextra.com/how-to-enable-remote-rest-api-on-docker-host/

Introduction

Docker provides remote REST API which is beneficial if you want to connect to a remote docker host. Few of the functions which you can achieve using Docker REST API over a simple browser are

Create and Manage Containers
Get low-level information about a container
Get Container Logs
Start/Stop container
Kill a container

My remote docker host was an Ubuntu Virtual Image on Microsoft Azure.

In this tutorial, I will show you

What didn’t worked?
What really worked.

Things that didn’t worked

Over the internet, most of the people have suggested editing DOCKER_OPTS variable.

I changed DOCKER_OPTS in the /etc/default/docker file but it didn’t have any effect
Then I tried changing DOCKER_OPTS in the file /etc/init/docker.conf but again no success.

What really worked for me to enable docker remote API on docker host

Navigate to /lib/system/system in your terminal and open docker.service file

vi /lib/systemd/system/docker.service
	
 
vi /lib/systemd/system/docker.service
 
Find the line which starts with ExecStart and adds  -H=tcp://0.0.0.0:2375 to make it look like

ExecStart=/usr/bin/docker daemon -H=fd:// -H=tcp://0.0.0.0:2375
	
 
ExecStart=/usr/bin/docker daemon -H=fd:// -H=tcp://0.0.0.0:2375
 
Save the Modified File
Reload the docker daemon

 systemctl daemon-reload
	
 
 systemctl daemon-reload
 
Restart the container

sudo service docker restart
	
 
sudo service docker restart
 
Test if it is working by using this command, if everything is fine below command should return  a JSON

curl http://localhost:2375/images/json
	
 
curl http://localhost:2375/images/json
 
To test remotely, use the PC name or IP address of Docker Host

steps

  • Navigate to /lib/systemd/system in your terminal and open docker.service file
  • vi /lib/systemd/system/docker.service
  • Find the line which starts with ExecStart and adds -H=tcp://0.0.0.0:2375 to make it look like
  • ExecStart=/usr/bin/dockerd -H=fd:// -H=tcp://0.0.0.0:2375
  • Save the Modified File
  • Reload the docker daemon
  • systemctl daemon-reload
  • sudo service docker restart
  • Test if it is working by using this command, if everything is fine below command should return a JSON
curl http://localhost:2375/images/json
  • To test remotely, use the PC name or IP address of Docker Host

from: https://blog.usejournal.com/how-to-enable-docker-remote-api-on-docker-host-7b73bd3278c6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment