Docker Swarm on AWS
https://docs.docker.com/machine/examples/aws/#step-1-sign-up-for-aws-and-configure-credentials
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/get-set-up-for-amazon-ec2.html
User létrehozása
Ahhoz hogy a docker-machine be tudjon lépni az AWS account-unkba, létre kell hozni egy IAM (Identity and Access Management) adminisztrátor jogú user-t. https://console.aws.amazon.com/iam
A user létrehozása közben kapni fogunk egy access-id-t és egy egy titkos kulcsot. Ezt a kettőt kell majd megadni a docker-machine-nak.
Létre kell hozni egy credentials fájlt a .aws mappában. Alapértelmezetten itt keresni majd az aws driver. Másoljuk bele az id-t és a kulcsot:
~/.aws/credentials
[default] aws_access_key_id = AKIAJ622JUHS4RIJOI3A aws_secret_access_key = XXXXXXXXXXXXXXXXXXXXXXXXXXX
VM létrehozása
Az amaozon driver alapértelmezetten benne van a docker-machine-ben, nem kell külön telepíteni mint a KVM esetén láttuk. Ha ingyenes VM-et akarunk megadni, akkor használjuk a t2.micro típust.
Meg kell adni, hogy melyik klászterben van az amazon előfizetésünk. Ez az EC2 Dashboard-on is látszik, illetve az URL-ből is (https://ap-southeast-1.console.aws.amazon.com). A minek a szingapúri 1-es ben van.
Ezen felül fontos hogy megadjuk, hogy az új VM-en melyik portok legyenek nyitva. Alapértelmezetten csak a 22 SSH és a 2375 Docker port van nyitva.
Az amaznec2 driver alapértelmezetten ubuntu image-t telepít az új VM-ekre.
# docker-machine create --driver amazonec2 \ --amazonec2-instance-type "t2.micro" \ --amazonec2-region ap-southeast-1 \ --amazonec2-open-port 8080 docker-sendbox
Running pre-create checks... Creating machine... (docker-sendbox) Launching instance... 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(systemd)... 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... Docker is up and running! To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env docker-sendbox
Mi jött létre
# docker-machine ls NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS docker-sendbox - amazonec2 Running tcp://54.169.84.170:2376 v18.05.0-ce
# docker-machine ssh docker-sendbox Welcome to Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-1020-aws x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage Get cloud support with Ubuntu Advantage Cloud Guest: http://www.ubuntu.com/business/services/cloud 184 packages can be updated. 92 updates are security updates. ubuntu@docker-sendbox:~$
ubuntu@docker-sendbox1:~$ sudo docker run -dit --name apache -p 8080:80 httpd:2.4 Unable to find image 'httpd:2.4' locally 2.4: Pulling from library/httpd 1c7fe136a31e: Pull complete 72d2d593b3a7: Pull complete 96cd507e10fd: Pull complete ec6bb3492a46: Pull complete 0ea3a980fa47: Pull complete ebe42c0aa1a8: Pull complete a640bae86fe0: Pull complete Digest: sha256:963ecd717afb125c7a867d82d6935930bb93acc5078ea8bc37854d4b4de766d9 Status: Downloaded newer image for httpd:2.4 21b8f150ed88434b73a95e47a4a07c78859965c19325b08578b11aca3dcc4761
ubuntu@docker-sendbox:~$ sudo docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 2d6843f4f464 httpd:2.4 "httpd-foreground" 41 seconds ago Up 40 seconds 0.0.0.0:8080->80/tcp apache
# docker-machine rm -f docker-sendbox About to remove docker-sendbox1 WARNING: This action will delete both local reference and remote instance. Successfully removed docker-sendbox1