Configure environment variables

To simplify the parameters that are used each time a Docker Machine command is run, configure the environment variables as follows:

export DEBUG=true 
export ECS_ACCESS_KEY_ID=<your_access_key_id> 
export ECS_ACCESS_KEY_SECRET=<your_access_key_secret> 
export ECS_REGION=<your_ecs_region>
export ECS_SSH_PASSWORD=<your_ssh_password> 
export MACHINE_DOCKER_INSTALL_URL= http://acs-public-mirror.oss-cn-hangzhou.aliyuncs.com/docker-engine/internet
# Optional for VPC only
export ECS_VPC_ID=<your_vpc_id>
export ECS_VSWITCH_ID=<your_vswitchid>
Note
  • ECS_REGION indicates the region in which your Elastic Compute Service (ECS) instance resides, such as cn-beijing, cn-hangzhou, and cn-qingdao.
  • ECS_SSH_PASSWORD indicates the password you set for logging on to your ECS instance by means of SSH. The password is 8–30 characters long and must contain uppercase letters/lowercase letters, numbers, and special characters at the same time. However, the password does not support backward slash (\) or double quotation mark (“). For more information, see the ECS instance document CreateInstance.
  • Configure the MACHINE_DOCKER_INSTALL_URL environment variable to the preceding Alibaba Cloud image site because the access to the Docker Engine official repository from China is unstable. Otherwise, errors such as Error Creating machine: Error running provisioning: error installing docker may be returned when you create an ECS instance. You can use  http://acs-public-mirror.oss-cn-hangzhou.aliyuncs.com/docker-engine/intranet as the installation image of Docker Engine in the Alibaba Cloud intranet.
  • Do not configure the ECS_VPC_ID or ECS_VSWITCH_ID environment variables unless you have VPC configurations. If you have a VPC-related account, make sure that your current ECS_REGION supports VPC configurations.

Use ECS Driver to create and delete ECS instances

After environment variables are configured, most parameters can be replaced by those environment variables by default.

You can create an ECS instance that contains the Docker environment by running the following command.

docker-machine create -d aliyunecs dev1

The example output is as follows:

$ docker-machine create -d aliyunecs dev1
Running pre-create checks...
Creating machine...
Waiting for machine to be running, this may take a few minutes...
Machine is running, waiting for SSH to be available...
Detecting operating system of created instance...
Provisioning created instance...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
To see how to connect Docker to this machine, run: docker-machine env dev1

Run the docker-machine ls  command to view the created ECS instance that contains the Docker environment.

$ docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM
dev1 - aliyunecs Running tcp://1.2.7.2:9376

Run the docker-machine kill command to stop the ECS instance and view the instance status.

$ docker-machine kill dev1
$ docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM
dev1 - aliyunecs Stopped tcp://1.2.7.2:9376

Run the docker-machine rm command to delete the ECS instance and view the instance information (you can directly run this command without running the docker-machine kill command first).

$ docker-machine rm dev1
Successfully removed dev1
$ docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM

For more docker-machine commands, see Docker Machine command-line reference.