docker-machine – Adim 2

docker-machine windows ve Mac OSX gibi isletim sistemleri uzerinden birden fazla Docker Host’u manage etmek icin kullanilan bir binary.

Ben Mac OSX kullanicisiyim ve makinemde Docker Toolbox kurulu ki icersinde  docker-machine iceriyor , yok ise edinin kendisi ek olarak Linux ve Windows icinde mevcut.

docker-machine tek bir noktadan networkunuzdeki docker host’lari yonetebildigi gibi Digital Ocean , Openstack ve diger cloud provider’lardaki kaynak havuzunuzda docker host’lar hazirlayabilir ve yonetebilirsiniz.

Bu makalede generic driver kullanarak hali hazirda uzerinde ubuntu kurulu bir VM i sisteme tanitacagim (hatta oncesinde uzerinde Docker da kurulmus yani existing docker host’u ekliyoruz)

Simdi asil amacim docker-machine ile docker host’lari yonetmekten cok karsilastigim hatalar ve cozumleri belirtmek.

Herkes yaratarak baslar , biz silerek baslayalim ama oncesinde bir listeleyelim ne var diye ….

vahric:.ssh vahricmuhtaryan$ docker-machine ls

NAME       ACTIVE   DRIVER    STATE     URL                        SWARM   DOCKER    ERRORS

docker01   –        generic   Running   tcp://10.111.21.210:2376           Unknown   Unable to query docker version: Unable to read TLS config: open /Users/vahricmuhtaryan/.docker/machine/machines/docker01/server.pem: no such file or directory

docker02   –        generic   Running   tcp://10.111.21.210:2376           Unknown   Unable to query docker version: Unable to read TLS config: open /Users/vahricmuhtaryan/.docker/machine/machines/docker02/server.pem: no such file or directory

Sonra silelim

vahric:.ssh vahricmuhtaryan$ docker-machine rm docker01

About to remove docker01

Are you sure? (y/n): y

Successfully removed docker01

 

Simdi Docker-Host’u eklemeye calisalim , cok guzel cakiliyorsunuz … 

Oncelikle docker-machine komutlarini calistiracagimiz makinenin yonetecegi docker node’larina sifresiz SSH yapabiliyor olmasi lazim , bunu icin eger makinenizde SSH public ve private key’ler yok ise ssh-keygen komutu ile yaratin. Ek bir parametre koymaya gerek yok, sadece ilgili komutu yazin ve calisitirin size gelen sorulara enter layarak ve herhangi bir sifre set etmeyip enter’layip gecin.

Ikinci adimda yaratilan public key’i ilgili docker node’larina aktarin , bunun icin asagidaki komutu calistirin. Sifreyi girdikten sonra ilgili kullanicinin home dizni altindaki .ssh klasorunde “authorized_keys” dosyasinda public key’inizi goreceksiniz.

ssh-copy-id <kullanici>@<ip>

Bilenler belki eksik komut yazdigimi dusunebilirler, yanlisliklar yapmisimdirda ama hatalar guzel, sonradan cozecegiz hepsini

vahric:.ssh vahricmuhtaryan$ docker-machine create –driver generic –generic-ip-address=10.111.21.210 –generic-ssh-key=id_rsa docker01

Running pre-create checks…

Creating machine…

(docker01) Importing SSH key…

Waiting for machine to be running, this may take a few minutes…

Detecting operating system of created instance…

Waiting for SSH to be available…

Burada hemen bir debug girisimi ….. (Bu arada unutmayin her denemede bir takim kayitlar olusacak ayni isimle farkli denemeler yapmak istediginizde already exist ler alacaksiniz, oncesinde silmeyi unutmayin )

–debug o kadar guzel bir yere konmali ki calissin diye🙂 Asagidaki ciktinin en sonuna bakin ahanda root@10.111.21.210 olarak  deniyormus ondan waiting for SSH da kaliyor , ubuntu kurulumunda sadece sudo yapabilen “noroot” kullanicim vardi , ne root aktif nede sifresi vardi …..

vahric:.ssh vahricmuhtaryan$ docker-machine –debug create –driver generic –generic-ip-address=10.111.21.210 –generic-ssh-key=id_rsa docker02

Docker Machine Version:  0.7.0, build a650a40

Found binary path at /usr/local/bin/docker-machine

Launching plugin server for driver generic

Plugin server listening at address 127.0.0.1:60611

() Calling .GetVersion

Using API Version  1

() Calling .SetConfigRaw

() Calling .GetMachineName

(flag-lookup) Calling .GetMachineName

(flag-lookup) Calling .DriverName

(flag-lookup) Calling .GetCreateFlags

Found binary path at /usr/local/bin/docker-machine

Launching plugin server for driver generic

Plugin server listening at address 127.0.0.1:60615

() Calling .GetVersion

Using API Version  1

() Calling .SetConfigRaw

() Calling .GetMachineName

(docker02) Calling .GetMachineName

(docker02) Calling .DriverName

(docker02) Calling .GetCreateFlags

(docker02) Calling .SetConfigFromFlags

Running pre-create checks…

(docker02) Calling .PreCreateCheck

(docker02) Calling .GetConfigRaw

Creating machine…

(docker02) Calling .Create

(docker02) Importing SSH key…

(docker02) Calling .GetConfigRaw

(docker02) DBG | IP: 10.111.21.210

(docker02) Calling .DriverName

(docker02) Calling .DriverName

Waiting for machine to be running, this may take a few minutes…

(docker02) Calling .GetState

Detecting operating system of created instance…

Waiting for SSH to be available…

Getting to WaitForSSH function…

(docker02) Calling .GetSSHHostname

(docker02) Calling .GetSSHPort

(docker02) Calling .GetSSHKeyPath

(docker02) Calling .GetSSHKeyPath

(docker02) Calling .GetSSHUsername

Using SSH client type: external

Using SSH private key: /Users/vahricmuhtaryan/.docker/machine/machines/docker02/id_rsa (-rw——-)

&{[-F /dev/null -o BatchMode=yes -o PasswordAuthentication=no -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=quiet -o ConnectionAttempts=3 -o ConnectTimeout=10 -o ControlMaster=no -o ControlPath=none root@10.111.21.210 -o IdentitiesOnly=yes -i /Users/vahricmuhtaryan/.docker/machine/machines/docker02/id_rsa -p 22] /usr/bin/ssh <nil>}

About to run SSH command:

exit 0

Simdi kullaniciyi ekleyelim birde boyle deneyelim , tek yaptigimiz kullanici belirtmek ama yine patlayacak

docker-machine –debug create –driver generic –generic-ip-address=10.111.21.210 –generic-ssh-user=noroot –generic-ssh-key=id_rsa docker01

Hata –> sudo: no tty present and no askpass program specified

Bize diyor ki sifresizde sudo komutunu kullanmak icin bisiler yapmalisin :( Ilgili satiri –> sudo vi /etc/sudoers <– ekleyin ve  –> wq! <– diyip cikin dosyadan )

noroot ALL= (root) NOPASSWD:ALL

Tekrar deneyelim , goreceksiniz ki hosts dosyasi guncelleme , apt repo guncelleme , docker kurma gibi islemler yapilacak🙂

Ilgili komut calistirdigimida soyle bir cikti verdi bana fakat docker-host lari listeledigimde asagidaki gibi calisiyor gozukuyor.

You can attempt to regenerate them using ‘docker-machine regenerate-certs [name]’.

Be advised that this will trigger a Docker daemon restart which will stop running containers.

vahric:.ssh vahricmuhtaryan$ docker-machine ls

NAME       ACTIVE   DRIVER    STATE     URL                        SWARM   DOCKER    ERRORS

docker01   –        generic   Running   tcp://10.111.21.210:2376           v1.11.0

Ilk kurulumumda bunla karsilastim , ilgili komutu docker-machine regenerate-certs docker01 olarak calistirdim , hatta docker01 makinesinde docker servisinide restart ettim ve calisti

Ilerleyen zamanlarda ayni islemi “v1.12.3” version docker ile yaptigimda regenerate-certs yapma ihtiyacim olmadi.

Simdi sifir kurulu bir ubuntu node’u uzaktan Docker-Host olarak ayarlayalim

Bu arada ufak bir hatirlatma, ilgili islem oncesinde yine sifresiz sudo calistirma izni verdik ayni zamanda sudo hakki olan default kullandigim “noroot” kullanicisina docker komutlarini calistirma hakki vermek icin kendisini docker gurubuna ekledim “sudo gpasswd -a noroot docker veya sudo usermode -aG docker noroot

vahric:.ssh vahricmuhtaryan$ docker-machine create –driver generic –generic-ip-address=10.111.21.211 –generic-ssh-user=noroot –generic-ssh-key=id_rsa docker02

Running pre-create checks…

Creating machine…

(docker02) Importing SSH key…

Waiting for machine to be running, this may take a few minutes…

Detecting operating system of created instance…

Waiting for SSH to be available…

Detecting the provisioner…

Provisioning with ubuntu(upstart)…

Installing Docker…

Copying certs to the local machine directory…

Copying certs to the remote machine…

Setting Docker configuration on the remote daemon…

Checking connection to Docker…

Error creating machine: Error checking the host: Error checking and/or regenerating the certs: There was an error validating certificates for host “10.111.21.211:2376”: remote error: bad certificate

You can attempt to regenerate them using ‘docker-machine regenerate-certs [name]’.

Be advised that this will trigger a Docker daemon restart which will stop running containers.

Simdi iki tane oldu … 

vahric:.ssh vahricmuhtaryan$ docker-machine ls

NAME       ACTIVE   DRIVER    STATE     URL                        SWARM   DOCKER    ERRORS

docker01   –        generic   Running   tcp://10.111.21.210:2376           v1.11.0

docker02   –        generic   Running   tcp://10.111.21.211:2376           v1.11.0 

Dikkat ederseniz ACTIVE diye bir kolon var, bu kolon islemleri hangi docker-host icin yapacaginizi belirtir , gecis yapmak icin asagidaki komutu kullanarak bir docker-host dan diger docker-host’a gecebilirsiniz.

vahric:.ssh vahricmuhtaryan$ eval $(docker-machine env docker02)

Not : Neler oldugunu gormek icin cli da export demeniz yeterli veya yukardaki komutu calistirmadan once sunuda diyebilirsiniz ”

docker-machine env docker02” bu size calistirmaniz gereken komutu verecektir.

declare -x DOCKER_CERT_PATH=”/Users/vahricmuhtaryan/.docker/machine/machines/docker02″

declare -x DOCKER_HOST=”tcp://10.111.21.211:2376″

declare -x DOCKER_MACHINE_NAME=”docker02″

declare -x DOCKER_TLS_VERIFY=”1″

Bundan sonra tum docker komutlarini (docker ps , docker run) aktif olan docker-host icin kullanabilirsiniz

VM

Seri Hakkinda

1 – Hizlica ve Esitliklerle Docker

2 – docker-machine

3 – docker cok kullanilan komutlar kisa kisa

Posted on 25/04/2016, in Docker and tagged , , , , . Bookmark the permalink. 1 Comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: