<p>Correct me if I am wrong, but that is one of the reasons why docker orchestration tools exists like docker-swarm to be able to deploy multiple docker containers by using one command line.</p>

<blockquote>
  <p>Create a service with 5 replica tasks (–replicas)</p>
  
  <p>Use the --replicas flag to set the number of replica tasks for a replicated service. The following command creates a redis service with
  5 replica tasks:</p>

<pre><code>$ docker service create --name redis --replicas=5 redis:3.0.6

4cdgfyky7ozwh3htjfw0d12qv
</code></pre>
</blockquote>

<p>If for example 1000 identical containers that use a different environment variable have to be deployed, multiple <code>docker service create</code> could be added to a script, instead of copy-paste multiple times in one docker-compose file.</p>

CC BY-SA 3.0
2017-12-31T12:48:05.517Z
2017-12-31T12:48:05.517Z
030
<p>Docker compose allows for static stack description.
But what if I have a set of containers based on same image but different by subtle environment configuration? Moreover, I don't need them all at once, they can be launched and disposed of sequentially.</p>

<p>A quick shot would be to copy-paste the service, but a couple of dozens of them is a waste of resources.</p>

<p>Is there sort of elegant orchestration loop in this case?</p>

<p>UPD After some more googling, interesting fact came out that apparently what I do is batch job processing which has currently no conceptual (!) support in Docker compose because services are not batch jobs. While there is a <a href="https://github.com/moby/moby/issues/23880" rel="nofollow noreferrer">proposed feature for that</a> I will try out one of the community workarounds, <a href="https://github.com/alexellis/jaas" rel="nofollow noreferrer">Jobs As A Service (JaaS)</a> but my question is still - maybe there is an elegant way to do the following:</p>

<pre><code>version: '3.1'

services:

  task1:
    image: myjob
    environment:
      PARAM: foo

  task2:
    image: myjob
    environment:
      PARAM: bar
</code></pre>

<p>You may have asked yourself "why not just take a series of <code>docker run/exec/rm</code>", but the rest of the environment like database runs in the stack.</p>

<docker>
Reuse of docker swarm containers for batch jobs
Ta Mu
# Reuse of docker swarm containers for batch jobs

(Asked by: username_0 on 2017-07-29)

Docker compose allows for static stack description.
But what if I have a set of containers based on same image but different by subtle environment configuration? Moreover, I don't need them all at once, they can be launched and disposed of sequentially.
A quick shot would be to copy-paste the service, but a couple of dozens of them is a waste of resources.
Is there sort of elegant orchestration loop in this case?
UPD After some more googling, interesting fact came out that apparently what I do is batch job processing which has currently no conceptual (!) support in Docker compose because services are not batch jobs. While there is a proposed feature for that I will try out one of the community workarounds, Jobs As A Service (JaaS) but my question is still - maybe there is an elegant way to do the following:
version: '3.1'

services:

  task1:
    image: myjob
    environment:
      PARAM: foo

  task2:
    image: myjob
    environment:
      PARAM: bar

You may have asked yourself "why not just take a series of docker run/exec/rm", but the rest of the environment like database runs in the stack.

**Tags:** docker


---

## 1 answers

### Answer by username_1 on 2017-12-31. Score: 2 | Accepted answer

Correct me if I am wrong, but that is one of the reasons why docker orchestration tools exists like docker-swarm to be able to deploy multiple docker containers by using one command line.

Create a service with 5 replica tasks (–replicas)
Use the --replicas flag to set the number of replica tasks for a replicated service. The following command creates a redis service with
  5 replica tasks:
$ docker service create --name redis --replicas=5 redis:3.0.6

4cdgfyky7ozwh3htjfw0d12qv


If for example 1000 identical containers that use a different environment variable have to be deployed, multiple docker service create could be added to a script, instead of copy-paste multiple times in one docker-compose file.


---

