Using Docker-Swarm to duplicate Docker-Compose?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Using Docker-Swarm to duplicate Docker-Compose?

1,449 Views
Angelcrazy123
Contributor I

As part of my Docker Certification, I have to a project that contains 1 docker-compose file that runs 4 services that communicate with each other. These four services act like a 1 tank controller and 3 tank sensors. I want to duplicate the entire docker-compose with all four services using Docker Swarm. Here is an image of what I'm trying to do: an image showing the final goal

I am having a lot of confusion when setting up the docker swarm. I ran the following commands:

docker swarm init
docker stack deploy --compose-file=docker-compose.yml tank

But this set up only lets me scale one service at a time. For example:

docker service scale tank_lowlevelalarm=4

This isn't what I want to do. I want to be able to scale the entire docker-compose by replicating all four services at the same time. My goal is that on my overlay network, it will look like I have multiple tanks, and each tank has 1 controller and 3 sensors. Is it possible for me to do this?

My docker-compose file, for reference:

version: '3.0'
services:
  tli:
    image: tli
    networks:
      - my-overlay

  lowlvlalarm:
    image: lowlvlalarm
    build: .
    networks:
      - my-overlay

  highlvlalarm:
    image: highlvlalarm
    build: ./HighLvlAlarm
    networks:
      - my-overlay

  plc:
    image: plc
    depends_on:
      - tli
      - lowlvlalarm
      - highlvlalarm
    networks:
      - my-overlay

networks:
  my-overlay:  

 

0 Kudos
0 Replies
%3CLINGO-SUB%20id%3D%22lingo-sub-1242288%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EUsing%20Docker-Swarm%20to%20duplicate%20Docker-Compose%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1242288%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EAs%20part%20of%20my%20%3CA%20href%3D%22https%3A%2F%2Fintellipaat.com%2Fdocker-training-course%2F%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3EDocker%20Certification%3C%2FA%3E%2C%20I%20have%20to%20a%20project%20that%20contains%201%20docker-compose%20file%20that%20runs%204%20services%20that%20communicate%20with%20each%20other.%20These%20four%20services%20act%20like%20a%201%20tank%20controller%20and%203%20tank%20sensors.%20I%20want%20to%20duplicate%20the%20entire%20docker-compose%20with%20all%20four%20services%20using%20Docker%20Swarm.%20Here%20is%20an%20image%20of%20what%20I'm%20trying%20to%20do%3A%3CSPAN%3E%26nbsp%3Ban%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fi.stack.imgur.com%2FR5glO.jpg%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Eimage%20showing%20the%20final%20goal%3C%2FA%3E%3C%2FP%3E%3CP%3EI%20am%20having%20a%20lot%20of%20confusion%20when%20setting%20up%20the%20docker%20swarm.%20I%20ran%20the%20following%20commands%3A%3C%2FP%3E%3CPRE%3Edocker%20swarm%20init%0Adocker%20stack%20deploy%20--compose-file%3Ddocker-compose.yml%20tank%3C%2FPRE%3E%3CP%3EBut%20this%20set%20up%20only%20lets%20me%20scale%20one%20service%20at%20a%20time.%20For%20example%3A%3C%2FP%3E%3CPRE%3Edocker%20service%20scale%20tank_lowlevelalarm%3D4%3C%2FPRE%3E%3CP%3EThis%20isn't%20what%20I%20want%20to%20do.%20I%20want%20to%20be%20able%20to%20scale%20the%20entire%20docker-compose%20by%20replicating%20all%20four%20services%20at%20the%20same%20time.%20My%20goal%20is%20that%20on%20my%20overlay%20network%2C%20it%20will%20look%20like%20I%20have%20multiple%20tanks%2C%20and%20each%20tank%20has%201%20controller%20and%203%20sensors.%20Is%20it%20possible%20for%20me%20to%20do%20this%3F%3C%2FP%3E%3CP%3EMy%20docker-compose%20file%2C%20for%20reference%3A%3C%2FP%3E%3CPRE%3Eversion%3A%20'3.0'%0Aservices%3A%0A%20%20tli%3A%0A%20%20%20%20image%3A%20tli%0A%20%20%20%20networks%3A%0A%20%20%20%20%20%20-%20my-overlay%0A%0A%20%20lowlvlalarm%3A%0A%20%20%20%20image%3A%20lowlvlalarm%0A%20%20%20%20build%3A%20.%0A%20%20%20%20networks%3A%0A%20%20%20%20%20%20-%20my-overlay%0A%0A%20%20highlvlalarm%3A%0A%20%20%20%20image%3A%20highlvlalarm%0A%20%20%20%20build%3A%20.%2FHighLvlAlarm%0A%20%20%20%20networks%3A%0A%20%20%20%20%20%20-%20my-overlay%0A%0A%20%20plc%3A%0A%20%20%20%20image%3A%20plc%0A%20%20%20%20depends_on%3A%0A%20%20%20%20%20%20-%20tli%0A%20%20%20%20%20%20-%20lowlvlalarm%0A%20%20%20%20%20%20-%20highlvlalarm%0A%20%20%20%20networks%3A%0A%20%20%20%20%20%20-%20my-overlay%0A%0Anetworks%3A%0A%20%20my-overlay%3A%26nbsp%3B%26nbsp%3B%3C%2FPRE%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E