Skip to content

Instantly share code, notes, and snippets.

@maynero
Created August 8, 2021 21:22
Show Gist options
  • Save maynero/50d097fff04d2ff3c43f62f4b8572b68 to your computer and use it in GitHub Desktop.
Save maynero/50d097fff04d2ff3c43f62f4b8572b68 to your computer and use it in GitHub Desktop.
Enable docker remote API using bash
#!/bin/bash
# Absolute path of docker systemd file
dockersystemd='/lib/systemd/system/docker.service'
# Retrieve the line number of the ExecStart
execstartline=$(grep -n 'ExecStart=' ${dockersystemd} | cut -f1 -d':')
# New value of the ExecStart
newexecstart='ExecStart=/usr/bin/dockerd -H fd:// -H=tcp://0.0.0.0:2375 --containerd=/run/containerd/containerd.sock'
# Backup systemd file
cp -p ${dockersystemd} /tmp/docker.service.$(date '+%Y-%m-%d_%H%M%S').bak
# Update ExecStart with the new one
sed -i "${execstartline}s@.*@${newexecstart}@" ${dockersystemd}
# Reload and restart docker service
systemctl daemon-reload
systemctl restart docker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment