使用AWS docker machine
建置Docker Mahcine
使用AWS docker machine的語法:
$ docker-machine create \
--driver amazon \
--amazonec2-access-key xxxx \
--amazonec2-secret-key xxxx \
--amazonec2-vpc-id xxxx \
machine_name
ex:
$ docker-machine -D create aws-machine \
--driver amazonec2 \
--amazonec2-access-key AKIA....XPGQ \
--amazonec2-secret-key 44M...Rs/+zZI.....AO \
--amazonec2-vpc-id vpc-f...8 \
--amazonec2-zone e
Making AWS API call with values:
{
"Action": [
"DescribeKeyPairs"
],
"Version": [
"2014-06-15"
]
}
Making AWS API call with values:
{
"Action": [
"DescribeSubnets"
],
"Filter.1.Name": [
"availabilityZone"
],
"Filter.1.Value": [
"us-east-1e"
],
"Filter.2.Name": [
"vpc-id"
],
"Filter.2.Value": [
"vpc-f...8"
],
"Version": [
"2014-06-15"
]
}
Making AWS API call with values:
{
"Action": [
"DescribeKeyPairs"
],
"Version": [
"2014-06-15"
]
}
Launching instance...
creating key pair: aws-machine
Making AWS API call with values:
{
"Action": [
"ImportKeyPair"
],
"KeyName": [
"aws-machine"
],
"PublicKeyMaterial": [
"c3NoLXJzYSBBQUFB... (skip)
在AWS的docker machine上操作
$ docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM
aws-machine amazonec2 Running tcp://52.2.158.216:2376
default virtualbox Running tcp://192.168.99.100:2376
google-machine google Timeout
$ docker-machine env aws-machine
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://52.2.158.216:2376"
export DOCKER_CERT_PATH="/Users/peihsinsu/.docker/machine/machines/aws-machine"
export DOCKER_MACHINE_NAME="aws-machine"
# Run this command to configure your shell:
# eval "$(docker-machine env aws-machine)"
$ eval $(docker-machine env aws-machine)
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
$ docker run -it centos bash
Unable to find image 'centos:latest' locally
latest: Pulling from library/centos
47d44cb6f252: Pull complete
f6f39725d938: Pull complete
f9a8cbc8dd13: Pull complete
f37e6a610a37: Pull complete
0f73ae75014f: Pull complete
Digest: sha256:2d9573acf37315cb8fe2a1420769c3b83f59d8f286fd8898a580578c0d5e66c6
Status: Downloaded newer image for centos:latest
[root@be81c3b0683d /]#
關閉Docker Machine
當操作結束,不想要這台Docker Machine時,也可以透過docker machine的指令簡單地把AWS上的機器關閉:
$ docker-machine rm aws-machine
Successfully removed aws-machine