免責聲明

Disclaimer (免責聲明)
繼續閱覽代表您接受以上的免責聲明.
To continue reading means you accept the above disclaimer.

2015年3月25日 星期三

docker-machine example for ec2


//=== https://docs.docker.com/machine/

~$ ./docker-machine create ...
~$ ./docker-machine ls
~$ ./docker-machine ip
~$ ./docker-machine rm -f docker-node-name

[port 2376]
* ec2 security group 'docker-machine' needs modification to enhance security
TCP:2376 0.0.0.0/0 --> docker-machine-ip/32
SSH(TCP:22) 0.0.0.0/0 --> docker-machine-ip/32


//=== assume docker-machine is placed under ~/
given ec2 access-key and secret-key

~$ ./docker-machine create --driver "amazonec2"
--amazonec2-vpc-id "vpc-xxxxxxx"
--amazonec2-access-key "xxxxxxxxxxxxxxx"
--amazonec2-secret-key "yyyyyyyyyyyyyyyyyyy"
--amazonec2-region "us-west-1" ec2dk1

[create and launch ec2 instance named 'ec2dk1' (docker-node-name)
with docker daemon bound to port 2376 and
'docker-machine' security group assigned]

$ ./docker-machine ls

$ docker $(./docker-machine config ec2dk1) ps
[err]
2015/03/25 17:34:08 Get http://53.11.233.xxx:2376/v1.12/containers/json: malformed HTTP response "\x15\x03\x01\x00\x02\x02"

??? failed because the docker version installed by
'sudo apt-get install docker.io' is 1.0.1,
which is different from that created by docker-machine on the remote ec2 cloud

-->
~$ wget https://get.docker.com/builds/Linux/x86_64/docker-latest -O docker
~$ chmod +x docker
~$ ./docker $(./docker-machine config ec2dk1) ps


*** to make operation seamless
~$ $(./docker-machine env ec2dk1)
[ now docker points to ec2dk1,
$ echo $DOCKER_TLS_VERIFY
1

$ echo $DOCKER_HOST
tcp://53.11.233.xxx:2376

$ echo $DOCKER_CERT_PATH
/home/u13/.docker/machine/machines/ec2dk1
]

~$ ./docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

~$ ./docker images
~$ ./docker run -it --rm ubuntu:latest bash


//===
~$ ./docker ps
2015/03/25 19:10:58 Cannot connect to the Docker daemon. Is 'docker -d' running on this host?
--> remote docker daemon should be run with -H tcp://node-ip:2376

* docker-machine config.json
$ ls ~/.docker/machine/machines/ec2dk1/*.pem
$ cat ~/.docker/machine/machines/ec2dk1/config.json

{"DriverName":"none","Driver":{"URL":"tcp://54.69.237.148:2376"},
"CaCertPath":"/home/u13/.docker/machine/certs/ca.pem",
"ServerCertPath":"",
"ServerKeyPath":"",
"PrivateKeyPath":"/home/u13/.docker/machine/certs/ca-key.pem",
"ClientCertPath":"",
"SwarmMaster":false,
"SwarmHost":"tcp://0.0.0.0:3376",
"SwarmDiscovery":""}


*** Adding a host without a driver for an existing host
You can add a host to Docker which only has a URL without driver assigned
and can be used an alias for an "existing host" so you don’t have to type out the URL every time.

$ ./docker-machine create --url=tcp://docker-node-ip:2376 ec2dk0
$ docker-machine ls
NAME ACTIVE DRIVER STATE URL
ec2dk0 * none Running tcp://node-ip:2376

--> need ca.pem, ca-key.pem, ...

[Q] how to solve the problem caused by change of ndoe-ip after restarting ec2 instance ?



沒有留言:

張貼留言