Primary Menu

Run Docker Swarm with Upstart

In Ubuntu 14.04, to run a job in background an on startup, you should use Upstart. In this post, I will show you the way to run Swarm with Upstart. I think that it is more complicated that SystemD used by CoreOS or Ubuntu 15.04.

At the first, we need to open /etc/default/docker file and add a line:

1

DOCKER_OPTS="-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock"

And restart Docker:

1

service docker restart

We need to do this step so that Docker Daemon run at all interfaces and on port 2375. Now, you ready to run Swarm on the machine.

To run Swarm Join, you create file /etc/init/swarm-join.conf with content:

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

description"Swarm Join"

start on runlevel[2345]

stop on runlevel[!2345]

start on filesystem andstarted docker

setuid root

setgid root

# try to restart if crash

respawn limit3240

# start the container in the pre-start script

pre-start script

docker run-d--name swarm_joiner swarm join\

--addr=192.168.1.191:2375\

token://acdb9dfa3ea6da0b0cfb2c819385fcd3 # should change token and IP for your case

endscript

# run when container is running

script

sleepWhileAppIsUp(){

whiledocker ps|grep"$1">/dev/null;do

sleep2

done

}

sleepWhileAppIsUp"swarm_joiner"

endscript

# stop container when stop job

post-stop script

ifdocker ps|grep"swarm_joiner";

then

docker stop swarm_joiner

docker rm swarm_joiner

fi

endscript

Now, run Swarm Join job:

1

sudo start swarm-join

To run Swarm Manage, you create file /etc/init/swarm-manage.conf with content: