<p>Docker containers are isolated applications. When the application that it launches exits, the container also exits. So when your command is <code>ls</code>, that will run and then exit almost immediately, stopping the container.</p>

<p>Swarm mode has the goal to maintain a target state for your containers. By default, it will keep a single replica (instance of a container) of the service running. If the current state does not match the target state, it will take action to correct the issue. So for a container that has no running instances and a target replica count of 1, it will be constantly started.</p>

<p>So yes, this is an expected behavior given the inputs. Instead of <code>ls</code>, you should be using a long running daemon process.</p>

CC BY-SA 4.0
2018-06-04T17:59:54.167Z
2018-06-04T17:59:54.167Z
BMitch
<p>I have written my own simple docker <a href="https://hub.docker.com/r/briomkez/ethereum-test" rel="nofollow noreferrer">image</a>. It works fine.</p>

<p>Then I created my docker swarm with only two nodes a master and a slave and started a service with the following command:</p>

<p><code>docker service create  --mode global --name benchmark briomkez/ethereum-test</code></p>

<p>It loops, because it cannot create the service (the default command is a simple <code>ls</code>). </p>

<p>Why does this happen? Is it expected?</p>

<p>If I run the same service with a different command, e.g.:</p>

<p><code>docker service create  --mode global --name benchmark briomkez/ethereum-test geth</code></p>

<p>It works like a charm. Is this behavior expected, what is the motivation for the loop?</p>

<docker><docker-swarm>
Docker Swarm loop
Briomkez
# Docker Swarm loop

(Asked by: username_0 on 2018-06-04)

I have written my own simple docker [image](https://hub.docker.com/r/briomkez/ethereum-test). It works fine.

Then I created my docker swarm with only two nodes a master and a slave and started a service with the following command:

`docker service create --mode global --name benchmark briomkez/ethereum-test`

It loops, because it cannot create the service (the default command is a simple `ls`).

Why does this happen? Is it expected?

If I run the same service with a different command, e.g.:

`docker service create --mode global --name benchmark briomkez/ethereum-test geth`

It works like a charm. Is this behavior expected, what is the motivation for the loop?

**Tags:** docker, docker-swarm


---

## 1 answers

### Answer by username_1 on 2018-06-04. Score: 1 | Accepted answer

Docker containers are isolated applications. When the application that it launches exits, the container also exits. So when your command is `ls`, that will run and then exit almost immediately, stopping the container.

Swarm mode has the goal to maintain a target state for your containers. By default, it will keep a single replica (instance of a container) of the service running. If the current state does not match the target state, it will take action to correct the issue. So for a container that has no running instances and a target replica count of 1, it will be constantly started.

So yes, this is an expected behavior given the inputs. Instead of `ls`, you should be using a long running daemon process.


---

