Docker (v): Docker of the Three Musketeers

Source: Internet
Author: User
Tags docker for mac docker ps docker compose docker run docker toolbox docker machine

Previous article Docker (iv): Docker Compose of the Three Musketeers introduces Docker Compose, this article we'll look at Docker machine.

About Docker Machine

Docker Machine is one of the official Docker orchestration (Orchestration) projects that are responsible for quickly installing Docker environments on multiple platforms.

Docker Machine is a tool that allows you to install Docker engine on a virtual host and manage them using the Docker-machine command. You can use machine to create a Docker host on your local Mac or Windows box, corporate network, data center, or cloud provider like AWS or Digital Ocean.

With the Docker-machine command, you can start, review, stop, and restart managed host hosts, upgrade Docker clients and Daemons, and configure Docker clients to communicate with your host hosts.

Why use it?

Docker machine allows you to configure multiple remote Docker hosts on a variety of Linux.
In addition, machine allows you to run Docker on an earlier MAC or Windows system, as described in the previous topic.
Docker Machine has these two broad use cases.

    • I have an older desktop system and want to run Docker on MAC or Windows

If you're primarily working on an old Mac or a Windows laptop or desktop that doesn't meet the new Docker for Mac and Docker for Windows applications, you'll need Docker machine to "Run Docker" locally (ie Docke R Engine). Installing Docker machine with the Docker Toolbox installer in your Mac or Windows box will configure a local VM for Docker engine, allowing you to connect to it and run Docker commands.

    • I want to configure a Docker host on a remote system

Run natively on the Docker Engine Linux system. If you have a Linux as your main system and want to run the Docker command, all you need to do is download and install the Docker Engine. However, if you want to configure multiple Docker hosts on the network, in the cloud, or even locally, you need Docker machine.

Whether your main system is MAC, Windows or Linux, you can install Docker machine on it and use the Docker-machine command to configure and manage a large number of Docker hosts. It automatically creates a host, installs the Docker engine on it, and then configures the Docker client. Each managed host ("Machine") is a combination of a Docker host and a configured client.

What is the difference between Docker Engine and Docker machine?

When people say "docker," they usually refer to the Docker Engine, which is a client-server application that specifies the interface that interacts with the daemon by a Docker daemon, a rest API, and a command-line interface (CLI) to communicate with the daemon (by encapsulating the rest API). Docker Engine accepts Docker commands from the CLI, such as Docker run <image>, Docker PS to list the running containers, Docker images to list the mirrors, and so on.

Docker Machine is a tool for configuring and managing your Host (the one with Docker engine above). Typically, you install Docker machine on your local system. Docker machine has its own command-line client Docker-machine and Docker Engine client Docker. You can use machine to install Docker Engine on one or more virtual systems.

These virtual systems can be local (just like you install and run Docker Engine in VirtualBox with machine on MAC or Windows) or remotely (just as you use machine provision on a cloud provider Docke Rized host). Dockerized host itself can be considered, and sometimes called, managed "machines".

Installation and use

Docker Machine installation is simple

curl -L https://github.com/docker/machine/releases/download/v0.14.0/docker-machine-`uname -s`-`uname -m` >/tmp/docker-machine && install /tmp/docker-machine /usr/local/bin/docker-machine#完成后,查看版本信息。docker-machine -vdocker-machine version 0.14.0, build 89b8332
Create a VirtualBox

To see if there are available hosts

$  docker-machine lsNAME   ACTIVE   DRIVER   STATE   URL   SWARM   DOCKER   ERRORS

Create a host:

$ docker-machine Create--driver VirtualBox defaultrunning pre-create checks ... (default) Default Boot2docker ISO is out-of-date, downloading the latest release ... (default) Latest release for Github.com/boot2docker/boot2docker is V17.12.1-ce (default) downloading C:\Users\hkrt-neo\.docker\ Machine\cache\boot2docker.iso from https://github.com/boot2docker/boot2docker/releases/download/v17.12.1-ce/ Boot2docker.iso ... (default) 0% .... 10% ..... 20% ..... 30% ..... 40% ..... 50% ..... 60% ..... 70% ..... 80% ..... 90% ..... 100%creating machine ... (default) Copying C:\Users\hkrt-neo\.docker\machine\cache\boot2docker.iso to C:\Users\hkrt-neo\.docker\machine\machines\ Default\boot2docker.iso ... (default) Creating VirtualBox VM ... (default) Creating SSH Key ... (default) Starting the VM ... (default) Check network to re-create if needed ... (default) Windows might ask for the permission to configure a DHCP server. Sometimes, such confirmation window is minimized in the taskbar. (default) Waiting for an IP ... Waiting-to-be RUNning, this could take a few minutes ... Detecting operating system of created instance ... Waiting for SSH to be available ... Detecting the Provisioner ... Provisioning with Boot2docker ... Copying certs to the Local machine directory ... Copying certs to the remote ... Setting Docker configuration on the remote daemon ...

This command downloads Boot2docker and creates a virtual host based on Boot2docker. Boot2docker is a lightweight Linux distribution, based on the Tiny Core Linux system designed specifically for running Docker containers, running completely from RAM, around 45Mb, and starting at about 5s.

View the list of services again

docker-machine lsNAME      ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER        ERRORSdefault   *        virtualbox   Running   tcp://192.168.99.100:2376           v17.12.1-ce

Discover that a virtual host already exists

After the host has been created successfully, the ENV command can be used to make the subsequent operation objects a target host.

$ docker-machine env defaultexport DOCKER_TLS_VERIFY="1"export DOCKER_HOST="tcp://192.168.99.100:2376"export DOCKER_CERT_PATH="C:\Users\hkrt-neo\.docker\machine\machines\default"export DOCKER_MACHINE_NAME="default"export COMPOSE_CONVERT_WINDOWS_PATHS="true"# Run this command to configure your shell:# eval $("D:\Program Files\Docker Toolbox\docker-machine.exe" env default)

Equivalent to configuring an environment variable default, followed by the prompt to enter commands at the command line after you can manipulate the default host.

You can log on to the host via SSH

$ docker-machine ssh default[email protected]:~$ docker --versionDocker version 17.12.1-ce, build 7390fc6

After connecting to the host you can use Docker on it and exit the virtual machine using the command:exit

Common commands for Docker machine
//创建虚拟机docker-machine create [OPTIONS] [arg...]//移除虚拟机docker-machine rm [OPTIONS] [arg...]//登录虚拟机docker-machine ssh [arg...]//docker客户端配置环境变量docker-machine env [OPTIONS] [arg...]//检查机子信息docker-machine inspect//查看虚拟机列表docker-machine ls [OPTIONS] [arg...]//查看虚拟机状态docker-machine status [arg...]  //一个虚拟机名称//启动虚拟机docker-machine start [arg...]  //一个或多个虚拟机名称//停止虚拟机docker-machine stop [arg...]  //一个或多个虚拟机名称//重启虚拟机docker-machine restart [arg...]  //一个或多个虚拟机名称

For more parameters, use the Docker-machine--help command to view.

Summarize

The main two functions of Docker machine are:

    • Docker machine makes it easy to use Docker in different environments, such as: Win/mac
    • Use Docker machine for batch deployment of Docker environments in a cloud environment, such as: private cloud, public cloud batch installation Docker environment

VirtualBox installation was troublesome, I used the virtual machine and the cloud host to do the experiment did not install successfully, finally used the Docker provided by the Windows installation package to complete the VirtualBox-related operations. Attached VirtualBox official website: https://www.virtualbox.org/wiki/Downloads

Reference

Docker Machine Overview
Docker-machine Common Commands

Docker (v): Docker of the Three Musketeers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.