Benpian is about docker docker machine in The Three Musketeers.
Note: The environment for CentOS7, docker 19.03.
docker docker-machine is one of the official Three Musketeers project, which is a command-line tool. We use docker-machine environment can quickly create a docker. It also supports multiple cloud computing environments, allowing users to install and maintain docker operating environment on multiple platforms.
The figure is a schematic docker-machine, it is connected to a different type of platform is achieved by a corresponding drive, the former comprises a destination time has integrated ⽀ AWS, IBM, Google, and OpenStack, VirtualBox, vSphere other cloud platform hold.
Docker-machine installation
Docker-machine installation on linux only official release from the library directly download the compiled binary files to
base=https://github.com/docker/machine/releases/download/v0.16.0 &&
curl -L $base/docker-machine-$(uname -s)-$(uname -m) >/tmp/docker-machine &&
sudo mv /tmp/docker-machine /usr/local/bin/docker-machine
chmod +x /usr/local/bin/docker-machine
After installation is complete, view the version information:
# docker-machine version
docker-machine version 0.16.0, build 702c267f
docker-machine supports command completion, you need to download the file bash machine library
base=https://raw.githubusercontent.com/docker/machine/v0.16.0
for i in docker-machine-prompt.bash docker-machine-wrapper.bash docker-machine.bash
do
sudo wget "$base/contrib/completion/bash/${i}" -P /etc/bash_completion.d
done
Then execute
source /etc/bash_completion.d/docker-machine-prompt.bash
To enable docker-machine shell prompt, add $(__docker_machine_ps1)
to PS1 set in ~ / .bashrc.PS1='[\u@\h \W$(__docker_machine_ps1)]\$ '
Use docker-machine
Installation docker
docker-machine installation supports multiple environments, here we introduce several
virtualbox
docker-machine support through virtualbox drive installed and configured docker host, provided that I need to install virtualbox (https://www.virtualbox.org/wiki/Downloads)
docker-machine create --driver virtualbox default
genernic
genernic way can be installed via ssh directly on the remote docker, but before that must first configure ssh authentication
1. Generate Key
# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:V7kl+8c0paW/yGFCA+TOvBoH86MtLdKBBZ432TwlrN0 root@centos1
The key's randomart image is:
+---[RSA 2048]----+
| .. |
| . oo . . |
| . o *o+ + . o|
| o *+=.E = +.|
| +oS+ooo o..|
| . .+.o .. +.|
| ..o= . o. +|
| . +*.. + o..|
| .oo. o . |
+----[SHA256]-----+
2. Host installation key
# ssh-copy-id [email protected]
As a result the machine can not require a password to log the remote host.
3.genernic installation docker
# docker-machine create --driver generic --generic-ip-address 192.168.10.11 --generic-ssh-key ~/.ssh/id_rsa --generic-ssh-user=root centos2
Note: If you do not docker installed on the host, the waiting time will be longer this process.
4. View Host
# docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
centos2 - generic Running tcp://192.168.10.11:2376 v19.03.1
Other platforms
Installation for other platforms are not explained in detail here, if required, can be found https://docs.docker.com/machine.
docker-machine command
docker-machine provides a series of sub-commands corresponding to different functions.
Here are the commands specific usage
active
Format docker-machine active [arg...]
. ⽀ hold -timeout, -t "10"
option, on behalf of the timeout, the default is 10s. View the current Docker host active. Activation means that the current state of DOCKER_HOST environment variable to point to the host. For example, ⾯ command lists the currently active host dev Host:
# docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
centos2 - generic Running tcp://192.168.10.11:2376 v19.03.1
config
Format docker-machine config [OPTIONS] [arg...]
. ⽀ hold --swarm
parameters, monitor print Swarm cluster information table, ⽽ not Docker information. Check the connection configuration information Docker host. For example, the host dev ⾯ displayed connection information:
# docker-machine config centos2
--tlsverify
--tlscacert="/root/.docker/machine/machines/centos2/ca.pem"
--tlscert="/root/.docker/machine/machines/centos2/cert.pem"
--tlskey="/root/.docker/machine/machines/centos2/key.pem"
-H=tcp://192.168.10.11:2376
create
Format docker-machine create [OPTIONS] [arg...]
. Docker ⼀ create a host environment. ⽀ support options include:
- --driver, -d "virtualbox": specifies the type of drive;
- --engine-install-url "https://get.docker.com": when the installation URL Docker host configuration;
- --engine-opt option: to specify the parameters Docker key engine of creation of format;
- --engine-insecure-registry option: Docker on the format created to allow access to the engine do not support this warehouses holding registration authentication service specified in the key;
- --engine-registry-mirror option: Use designated-registered warehouses mirror;
- --engine-label option: Add tags for Docker engine created;
- --engine-storage-driver: rear drive type storage;
- --engine-env option: Specifies the environment variable;
- --swarm: Host Configuration Docker filling with the Swarm cluster;
- --swarm-image "swarm: latest": Using Swarm when recorded using a mirror;
- --swarm-master: configuring the machine as the master node of the cluster Swarm;
- --swarm-discovery: Swarm cluster service discovery mechanism parameters;
- --swarm-strategy "spread": Swarm default scheduling policy;
- --swarm-opt option: any of the parameters passed to Swarm;
- --swarm-host "tcp: //0.0.0.0: 3376": the specified address will listen Swarm master node request;
- --swarm-addr: Send Wide-broadcast filling with Swarm cluster service from the specified address.
For example, you can create a Docker ⼀ host virtual machine image with the following command:
# docker-machine create -d virtualbox \
--engine-storage-driver overlay \
--engine-label name=testmachine \
--engine-label year=2018 \
--engine-opt dns=8.8.8.8 \
--engine-env HTTP_PROXY=http://proxy.com:3128 \
--engine-insecure-registry registry.private.com \
mydockermachine
Docker Docker host virtual machine engine created:
- Using the overlay type of storage drive; - with name = testmachine year = 2015 and two labels;
- 8.8.8.8 engines are recorded using the default DNS;
- Environment variable to specify the HTTP proxy service http://proxy.com:3128.
- Use allowed without verification of registered warehouses registry.private.com.
env
Format docker-machine env [OPTIONS] [arg...]
. The monitor is connected to a host environment variables needed. ⽀ support options include:
· -swarm: displayed Swarm cluster configuration;
· -shell: Shell environment ⾯ to specify the default for the current Auto detection;
· -unset, -u: remove the corresponding environment variable;
· - no-proxy: add objects to the host address NO_PROXY environment variable.
For example, the monitor connected to the host default environment variables required:
# docker-machine env centos2
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.10.11:2376"
export DOCKER_CERT_PATH="/root/.docker/machine/machines/centos2"
export DOCKER_MACHINE_NAME="centos2"
# Run this command to configure your shell:
# eval $(docker-machine env centos2)
inspect
Format docker-machine inspect [OPTIONS] [arg...]
. Json output format to specify details Docker host. ⽀ hold -format, -f option to specify the Go Using the template formatted output.
ip
Gets the Docker host address. For example, the host obtains the address centos2, the following command can use it:
# docker-machine ip centos2
192.168.10.11
kill
Docker directly kill the specified host. Docker specified hosts will be strong ⾏ stops.
ls
Lists all hosts managed. Format docker-machine ls [OPTIONS] [arg...]
. It can be --filter
output only some Docker host, including the name of the filter holder ⽀ regular expressions, the drive type, the Swarm management node name, and status. E.g:
# docker-machine ls --filter state=Running
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
centos2 - generic Running tcp://192.168.10.11:2376 v19.03.1
⽀ support options include:
- --quiet, -q: Off ⽆ reduce output information;
- --filter [--filter option - filter option]: matching the filter output only the host;
- -timeout, -t "10": Perform command timeout, default is 10s;
- -format, -f: Use the specified template Go formatted output.