At the moment, docker swarm doesn’t have a self-discovery method. If you’ve mislaid or forgotten the discovery token you can’t add new elements. It just so happens that if you do a docker inspect $SWARM_AGENT_MASTER
, the token will show up in the command line arguments.
A lot of output is produced. However, the information is there. Next time remember the discovery token ;-).
Below is using docker machine
to get the configuration information to connect to the master. If the container is running locally, you could just do docker inspect
on the container. Otherwise you may need to specify the host with -H
or use other methods.
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
docker $(docker-machine config --swarm apis-rpi-dev) inspect apis-rpi-dev/swarm-agent-master [ { "Id": "29d2d82a89f3343f5d5fca4154aa218bbd6275f182919afa341522a45d0f1d18", "Created": "2015-09-05T23:51:23.256420183Z", "Path": "/swarm", "Args": [ "manage", "--tlsverify", "--tlscacert=/etc/docker/ca.pem", "--tlscert=/etc/docker/server.pem", "--tlskey=/etc/docker/server-key.pem", "-H", "tcp://0.0.0.0:3376", "--strategy", "spread", "token://F92E3C5D1B1ED415F8FC1F558CA9A812" ], "State": { "Running": true, "Paused": false, "Restarting": false, "OOMKilled": false, "Dead": false, "Pid": 2494, "ExitCode": 0, "Error": "", "StartedAt": "2015-09-05T23:51:24.63784709Z", "FinishedAt": "0001-01-01T00:00:00Z" }, "Image": "afa18e8db56f40cc3ca8a249640cc09d20fc2913a846535b7192e9e53b693253", "NetworkSettings": { "Bridge": "", "EndpointID": "90af57a50550fc0966a5b6de99fcc45380831d710d476ed4a9c655561d72ceca", "Gateway": "172.17.42.1", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "HairpinMode": false, "IPAddress": "172.17.0.1", "IPPrefixLen": 16, "IPv6Gateway": "", "LinkLocalIPv6Address": "", "LinkLocalIPv6PrefixLen": 0, "MacAddress": "02:42:ac:11:00:01", "NetworkID": "c9d310150c53f7134f6f19d5e31420a5dca158e209fdc3741b435989a6c9267a", "PortMapping": null, "Ports": { "2375/tcp": null, "3376/tcp": [ { "HostIp": "192.168.1.125", "HostPort": "3376" } ] }, "SandboxKey": "/var/run/docker/netns/29d2d82a89f3", "SecondaryIPAddresses": null, "SecondaryIPv6Addresses": null }, "ResolvConfPath": "/var/lib/docker/containers/29d2d82a89f3343f5d5fca4154aa218bbd6275f182919afa341522a45d0f1d18/resolv.conf", "HostnamePath": "/var/lib/docker/containers/29d2d82a89f3343f5d5fca4154aa218bbd6275f182919afa341522a45d0f1d18/hostname", "HostsPath": "/var/lib/docker/containers/29d2d82a89f3343f5d5fca4154aa218bbd6275f182919afa341522a45d0f1d18/hosts", "LogPath": "/var/lib/docker/containers/29d2d82a89f3343f5d5fca4154aa218bbd6275f182919afa341522a45d0f1d18/29d2d82a89f3343f5d5fca4154aa218bbd6275f182919afa341522a45d0f1d18-json.log", "Node": { "ID": "3YU6:B6MQ:L7MB:OFDX:MTMP:KNMY:5HN7:I2LL:JDZW:D7J3:DQOK:7K2K", "IP": "192.168.1.125", "Addr": "192.168.1.125:2376", "Name": "apis-rpi-dev", "Cpus": 4, "Memory": 970031104, "Labels": { "executiondriver": "native-0.2", "kernelversion": "3.18.11-hypriotos-v7+", "operatingsystem": "Raspbian GNU/Linux 7 (wheezy)", "provider": "hypriot", "storagedriver": "overlay" } }, "Name": "/swarm-agent-master", "RestartCount": 0, "Driver": "overlay", "ExecDriver": "native-0.2", "MountLabel": "", "ProcessLabel": "", "AppArmorProfile": "", "ExecIDs": null, "HostConfig": { "Binds": [ "/etc/docker:/etc/docker" ], "ContainerIDFile": "", "LxcConf": [], "Memory": 0, "MemorySwap": 0, "CpuShares": 0, "CpuPeriod": 0, "CpusetCpus": "", "CpusetMems": "", "CpuQuota": 0, "BlkioWeight": 0, "OomKillDisable": false, "MemorySwappiness": -1, "Privileged": false, "PortBindings": { "3376/tcp": [ { "HostIp": "", "HostPort": "3376" } ] }, "Links": null, "PublishAllPorts": false, "Dns": null, "DnsSearch": null, "ExtraHosts": null, "VolumesFrom": null, "Devices": [], "NetworkMode": "default", "IpcMode": "", "PidMode": "", "UTSMode": "", "CapAdd": null, "CapDrop": null, "GroupAdd": null, "RestartPolicy": { "Name": "always", "MaximumRetryCount": 0 }, "SecurityOpt": null, "ReadonlyRootfs": false, "Ulimits": null, "LogConfig": { "Type": "json-file", "Config": {} }, "CgroupParent": "", "ConsoleSize": [ 0, 0 ] }, "GraphDriver": { "Name": "overlay", "Data": { "LowerDir": "/var/lib/docker/overlay/afa18e8db56f40cc3ca8a249640cc09d20fc2913a846535b7192e9e53b693253/root", "MergedDir": "/var/lib/docker/overlay/29d2d82a89f3343f5d5fca4154aa218bbd6275f182919afa341522a45d0f1d18/merged", "UpperDir": "/var/lib/docker/overlay/29d2d82a89f3343f5d5fca4154aa218bbd6275f182919afa341522a45d0f1d18/upper", "WorkDir": "/var/lib/docker/overlay/29d2d82a89f3343f5d5fca4154aa218bbd6275f182919afa341522a45d0f1d18/work" } }, "Mounts": [ { "Name": "0dec2384d1d38176b6c7c1539e7d323cb2014ca7312c44cbd6d1ae4621e8abbd", "Source": "/var/lib/docker/volumes/0dec2384d1d38176b6c7c1539e7d323cb2014ca7312c44cbd6d1ae4621e8abbd/_data", "Destination": "/.swarm", "Driver": "local", "Mode": "", "RW": true }, { "Source": "/etc/docker", "Destination": "/etc/docker", "Mode": "", "RW": true } ], "Config": { "Hostname": "29d2d82a89f3", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "ExposedPorts": { "2375/tcp": {}, "3376/tcp": {} }, "PublishService": "", "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": [ "SWARM_HOST=:2375" ], "Cmd": [ "manage", "--tlsverify", "--tlscacert=/etc/docker/ca.pem", "--tlscert=/etc/docker/server.pem", "--tlskey=/etc/docker/server-key.pem", "-H", "tcp://0.0.0.0:3376", "--strategy", "spread", "token://F92E3C5D1B1ED415F8FC1F558CA9A812" ], "Image": "hypriot/rpi-swarm:latest", "Volumes": { "/.swarm": {} }, "VolumeDriver": "", "WorkingDir": "", "Entrypoint": [ "/swarm" ], "NetworkDisabled": false, "MacAddress": "", "OnBuild": null, "Labels": {} } } ] |
Note the token://
argument and copy the token. Or, if feeling lazy, you could:
1 2 3 |
matt@argentum:~$ export TOKEN=`docker $(docker-machine config --swarm apis-rpi-dev) inspect apis-rpi-dev/swarm-agent-master|grep 'token://'|sed -e 's/ *//'|head -1` matt@argentum:~$ echo $TOKEN "token://F92E3C5D1B1ED415F8FC1F558CA9A812" |