summaryrefslogtreecommitdiffstats
path: root/docker/docker_remote_api/enable_remote_api.sh
blob: 76e59b8505a152f6a1209ceccd60be4692ea3849 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
# SPDX-license-identifier: Apache-2.0

# ******************************
# Script to update the docker host configuration
# to enable Docker Remote API
# ******************************

if [ -f /etc/lsb-release ]; then
    #tested on ubuntu 14.04 and 16.04
    if grep -q "#DOCKER_OPTS=" "/etc/default/docker"; then
        cp /etc/default/docker /etc/default/docker.bak
        sed -i 's/^#DOCKER_OPTS.*$/DOCKER_OPTS=\"-H unix:\/\/\/var\/run\/docker.sock -H tcp:\/\/0.0.0.0:2375\"/g' /etc/default/docker
    else
        echo DOCKER_OPTS=\"-H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375\" >> /etc/default/docker
    fi
    service docker restart
    #docker start $(docker ps -aq)
elif [ -f /etc/system-release ]; then
        #tested on centos 7.2
    if grep -q "ExecStart=\/usr\/bin\/docker-current daemon" "/lib/systemd/system/docker.service"; then
            cp /lib/systemd/system/docker.service /lib/systemd/system/docker.service.bak
            sed -i 's/^ExecStart=.*$/ExecStart=\/usr\/bin\/docker daemon -H tcp:\/\/0.0.0.0:2375 -H unix:\/\/\/var\/run\/docker.sock  \\/g' /lib/systemd/system/docker.service
            systemctl daemon-reload
            systemctl restart docker
        else
            echo "to be implemented"
    fi
else
    echo "OS is not supported"
fi

# Issue Note for Ubuntu
# 1. If the configuration of the file /etc/default/docker does not take effect after restarting docker service,
#    you may try to modify /lib/systemd/system/docker.service
#    commands:
#    cp /lib/systemd/system/docker.service /lib/systemd/system/docker.service.bak
#    sed -i '/^ExecStart/i\EnvironmentFile=-/etc/default/docker' /lib/systemd/system/docker.service
#    sed -i '/ExecStart=\/usr\/bin\/dockerd/{;s/$/ \$DOCKER_OPTS/}' /lib/systemd/system/docker.service
#    systemctl daemon-reload
#    service docker restart
# 2. Systemd is a system and session manager for Linux, where systemctl is one tool for systemd to view and control systemd.
#    If the file /lib/systemd/system/docker.service is modified, systemd has to be reloaded to scan new or changed units.
#    1) systemd and related packages are available on the PPA. To use the PPA, first add it to your software sources list as follows.
#       add-apt-repository ppa:pitti/systemd
#       apt-get update
#    2) system can be installed from the PPS as follows.
#       apt-get install systemd libpam-systemd systemd-ui