0
respostas

Usando o Vagrant como solução para o Docker Swarm, ex do código que usei.

Como o docker-machine esta deprecated atualmente usei o Vagrant para montar o ambiente, segue um exemplo do código que montei com 3 vms:

Utilizei o Ubuntu 20.04

Código

$docker_script = <<-SCRIPT

apt-get update && apt-get install ca-certificates curl gnupg lsb-release -y

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

echo deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

apt-get update -y

apt-get install docker-ce docker-ce-cli containerd.io -y SCRIPT

Vagrant.configure("2") do |config| config.vm.box = "ubuntu/focal64"

VM DOCKER 1

config.vm.define "vm1" do |vm1|

  vm1.vm.provision "shell",
      inline: "echo vm1 > /etc/hostname && \
                hostname vm1"

  vm1.vm.provision "shell", inline: "cat /vagrant/configs/focal.pub >> .ssh/authorized_keys"

  vm1.vm.network "public_network" ,
    bridge: "enp2s0",
    ip: "192.168.100.241"

  vm1.vm.provision "shell", inline: $docker_script

  vm1.vm.provider "virtualbox" do |vm1|
      vm1.memory = 512
      vm1.cpus = 1
      vm1.name = "vm1"



  end

 end


 # VM DOCKER 2
   config.vm.define "vm2" do |vm2|

     vm2.vm.provision "shell",
         inline: "echo vm2 > /etc/hostname && \
                   hostname vm2"

     vm2.vm.provision "shell", inline: "cat /vagrant/configs/focal.pub >> .ssh/authorized_keys"

     vm2.vm.network "public_network" ,
       bridge: "enp2s0",
       ip: "192.168.100.242"

     vm2.vm.provision "shell", inline: $docker_script

     vm2.vm.provider "virtualbox" do |vm2|
         vm2.memory = 512
         vm2.cpus = 1
         vm2.name = "vm2"



     end

    end

    # VM DOCKER 3
      config.vm.define "vm3" do |vm3|

        vm3.vm.provision "shell",
            inline: "echo vm3 > /etc/hostname && \
                      hostname vm3"

        vm3.vm.provision "shell", inline: "cat /vagrant/configs/focal.pub >> .ssh/authorized_keys"

        vm3.vm.network "public_network" ,
            bridge: "enp2s0",
            ip: "192.168.100.243"

        vm3.vm.provision "shell", inline: $docker_script

        vm3.vm.provider "virtualbox" do |vm3|
            vm3.memory = 512
            vm3.cpus = 1
            vm3.name = "vm3"



        end

       end

end