실습으로 배우는 Docker 입문 | 5. Docker Machine으로 Windows에 Docker 포스트 만들기

이번에는 Docker Machine이라는 도구를 사용하여 Windows PC에 Docker 호스트를 만드는 방법을 소개한다. Docker 호스트란 Docker가 설치되어 사용할 수 있는 상태가 되어있는 환경이다. Docker 호스트를 만드는 방법에 대해서는 예전에 “Docker 이미지 컨테이너 관리 메커니즘“에서 Docker for Windows와 Docker Toolbox라는 GUI 툴을 소개했는데, 이번에는 다루려고 하는 Docker Machine은 CLI 도구이다. Docker Machine은 VirtualBox 등의 가상 환경 도구가 있으면, 단 한줄의 명령의 실행으로 Docker 호스트를 만들어 준다.

Docker 호스트를 만들 수 없다!

Docker Machine을 다루기 전에 먼저 Docker Machine이 등장한 경위를 대해 알아 보자.

Docker의 특징의 하나로서, 응용 프로그램의 이식성을 높여 준다는 것을 잘들 수 있다. 예전에 “Docker 이미지 컨테이너 관리 메커니즘“에서도 Docker의 특징은 응용 프로그램을 “다양한 환경에 배포할 수 있다"있다는 내용과, “한 번 응용 프로그램을 Docker 컨테이너의 이미지로 만들면 그대로 다양한 플랫폼에서 실행된다"고 설명하였다.

이런 이식성의 특징은 당연히 Docker를 이용할 수 있는 환경 즉, Docker 호스트 없이는 성립되지 않는다. Docker 호스트가 있어야 비로소 응용 프로그램에 높은 이식성을 가져올 수 있다.

그러나 Docker 호스트를 생성하는 것은 결코 쉬운 일이 아니다. 특히 Docker가 등장한 2013 년은 그랬다. 예를 들어, Docker 호스트를 생성하기 위해서는 OS가 있어야 하는데, 도대체 어떤 OS를 준비해야 좋을까? 사실 Docker가 등장한 초기에 지원된 OS는 Ubuntu 12.04/12.10 만 이었다. 그 버전의 Ubuntu 환경을 아니면 새로 만들거나 기존의 Ubuntu 아닌 Linux에서는 패치 등의 작업이 필요했던 것이다.

2013년 11월 출시한 Docker 0.7부터 모든 주요 Linux 배포판이 지원되었지만 Docker 호스트를 만들 수 있는 기술은 아직 그다지 발전하지 않았다고 말할 수 있다.

Boot2Docker의 등장

그러던 중 2013년 12월에 개최 된 Docker 회사의 이벤트에서 Boot2Docker가 발표되었다.

Boot2Docker는 가상 환경 도구인 VirtualBox에 Docker 호스트를 만드는 도구이다. 초기에는 Mac에서만 지원되고 있었지만, 후에 Windows도 지원되게 되었다.

Boot2Docker의 구성은 다음의 두 가지로 나눌 수 있다.

  1. Docker 호스트를 만드는 기반이 되는 OS 이미지 파일
  2. Docker 호스트를 작성 · 관리하는 위한 CLI 도구

Boot2Docker 개요

OS 이미지 파일은 Tiny Core Linux라는 가벼운 Linux를 기반으로 하고 있다. Ubuntu 등 다목적 서버용 OS와 달리 Docker 호스트에 필요한 최소한의 것들만 포함되어 있기 때문에, 크기는 수십 MB로 매우 가볍다.

CLI 도구 명령 이름은 init, up, down등 직관적으로 알기 쉽고, Linux에 대한 지식을 그다지 필요로 하지 않는다.

이러한 OS와 도구를 세트로 제공 해주는 덕분에 Docker 또는 Linux에 그다지 친숙하지 않은 사용자도 쉽게 확실하게 가벼운 Docker 호스트를 만들 수 있다는 것이다.

Docker Machine의 등장

Boot2Docker의 등장으로 Docker 호스트의 생성은 매우 간단 해졌다. 이 Boot2Docker의 후속으로 개발된 것이 Docker Machine이다. Docker Machine은 2014년 12월 DockerCon EU 에서 발표되었다.

Docker Machine은 Boot2Docker와 마찬가지로 간편하고 가벼운 Docker 호스트를 생성하고 관리 할 수있는 도구이다. 기술적으로도 다음과 같이 Boot2Docker의 성과를 계승 발전시킨 것으로 되어 있다.

  1. Docker 호스트를 만드는 기반이 되는 OS 이미지 파일은 Boot2Docker 등의 이미지를 사용할 수 있다.
  2. Docker 호스트를 작성 · 관리하기위한 CLI 도구에서는 Boot2Docker에서 마이그레이션 되었다.
  3. 가상 환경으로는 VirtualBox뿐만 아니라 Hyper-V와 AWS 등 다양한 것들을 이용 가능하다.

Docker Machine 개요

이 중 Boot2Docker과 가장 크게 다른 점은 3번 가상 환경이다. Docker Machine은 드라이버라는 구조를 가지고 있으며, VirtualBox 드라이버와 AWS 드라이버 등 드라이버를 구분하여 다양한 가상 환경에 Docker 호스트를 작성할 수 있게 되었다. 현재는 10여가지 종류의 드라이버가 미리 Docker Machine에 내장되어 있다. 또한 드라이버는 직접 만드는 것도 가능하며, 20개 이상의 타사 드라이버가 존재한다.

Docker Machine 덕분에 Docker 호스트의 생성은 더욱 쉬워졌습니다. 이 후에도 Docker 호스트를 만들기위한 새로운 도구가 개발되어갑니다 만, 그것에 대해 마지막 정리로 설명한다.

사전 준비

그럼, 여기에서 Docker Machine의 구체적인 사용법에 대해 소개하겠다. 개요는 다음과 같다.

  • 사전 준비
  • Docker Machine 설치
  • Docker 호스트 만들기
  • Docker 호스트에 로그인
  • Docker 호스트에서 Hello World

우선 사전 준비로 Windows 10에 VirtualBox 를 설치한다. 그러고 당연히 되겠지만 PowerShell 명령을 실행할 수 있는지 확인한다.

여기서 필자가 이용한 환경은 다음과 같다.

  • Windows 10 Pro
  • VirtualBox 6.1.22
  • PowerShell 5.1.19041.1023

각각 간단하게 설명하겠다.

Windows 10

Docker 호스트를 만드는 최신 도구로 “Docker for Windows"라는 도구는 Windows 10 이상에서 동장하지만, Docker Machine은 Windows 7 이상부터 동작한다. 혹시 Windows 7 이하 버전을 사용하는 사람이 있다면 참고 바란다.

VirtualBox

VirtualBox는 Docker Machine의 기본 가상 환경 도구이다. Windows 용 설치 프로그램은 여기에서 다운로드 할 수 있다. 앞에서 설명하였듯이 Docker Machine은 AWS 등도 사용할 수 있지만, 우선 Boot2Docker에 있어서, 문제 해결 정보도 풍부한 VirtualBox를 사용하는 것을 추천한다.

참고로 Windows에 Hyper-V를 사용하고 싶은 경우는 Hyper-V와 VirtualBox를 동시에 사용하는 것은 기술적으로 불가능하므로 주의하시기 바란다.

PowerShell

Windows의 CLI로써, 명령 프롬프트를 떠올리는 사람이 많다고 생각되지만, 여기서는 PowerShell을 사용한다.

PowerShell은 Windows에 처음부터 설치되어 있지만 Windows 7의 경우 이전 버전 가능성이 높다. PowerShell 버전은 PowerShell에서 다음과 같이 입력하면 표시된다.

PS C:\> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.19041.1023

(이하 생략)

$PSVersionTable 버전 정보가 저장되는 변수로써 PowerShell이 자동으로 생성된다.

Docker Machine 설치

이것으로 사전 준비가 완료되면 Docker Machine을 설치해 보자. 설치는 간단하다. 바이너리 파일을 다운로드하여 Path를 설정하기만 하면 된다.

이번 이용하는 Docker Machine 버전은 v0.16.2이다. 바이너리 파일은 Docker Machine의 GitHub의 페이지 에서 다운로드할 수 있다. Windows 64 비트 버전의 파일 이름은 “docker-machine-Windows-x86_64.exe” 이다. 다운로드한 파일 이름을 “docker-machine.exe"으로 변경하고 적당한 장소에 저장하도록 한다. 여기에서는 아래와 같이 다음 위치에 파일이 있다는 전제로 설명하겠다.

C:\docker\docker-machine.exe

동작 확인을 위해 PowerShell을 열고 다음 명령을 실행하자.

PS C:\> C:\docker\docker-machine.exe version
docker-machine.exe version 0.16.2, build bd45ab13

버전 정보가 출력된다.

매번 이렇게 긴 경로와 함께 명령어를 입력할 수 불편하니, 윈도우 환경 변수 Path에 C:\docker를 추가하도록 하자(환경 변수에 추가하는 방법은 검색해 보면 흔하게 찾을 수 있을 것이다). 그러고 PowerShell을 다시 시작하고 다음 명령을 실행한다.

PS C:\> docker-machine version
docker-machine.exe version 0.16.2, build bd45ab13
PS C:\>

정보가 출력되면 성공이다. 아까와 달리 docker-machine끝에 .exe 붙이지 않았다. .exe이 있어도 동작하지만 이렇게 생략해도 된다.

이제 설치가 완료되었다. 드디어 실제로 Docker Machine을 동작시켜 Docker 호스트를 만들어 보자.

Docker 호스트 만들기

Docker Machine은 다음 단 한줄의 명령을 실행하면 Docker 호스트를 만들어줍니다.

PS > docker-machine create --driver virtualbox devkumahost

주의 : 기존에 이미 Hyper-V가 설치되어 있다면 docker-machine create 명령어를 실행하면 아래와 같이 명령어 발생할 것이다.

PS C:\> docker-machine create --driver virtualbox devkumahost
Creating CA: C:\Users\kimkc\.docker\machine\certs\ca.pem
Creating client certificate: C:\Users\kimkc\.docker\machine\certs\cert.pem
Running pre-create checks...
Error with pre-create check: "This computer is running Hyper-V. VirtualBox won't boot a 64bits VM when Hyper-V is activated. Either use Hyper-V as a driver, or disable the Hyper-V hypervisor. (To skip this check, use --virtualbox-no-vtx-check)"

위에서 언급 했듯이 Hyper-V와 VirtualBox를 동시에 사용하는 것은 기술적으로 불가능하므로, 둘 중에 하나를 사용하지 말아야 한다. 여기 예에서는 VirtualBox를 사용할 것이기에 Hyper-V 기능을 끄기로 하겠다. 끄는 방법은 [제어판>프로그램]에 가서 “Windows 기능 켜기/끄기"에서 Hyper-V 관련 옵션을 빼고 재부팅하면 된다.

create는 Docker 호스트를 작성하는 명령으로 devkumahost는 Docker 호스트의 이름이다. --driver(또는 -d) 드라이버를 지정하는 옵션으로, 여기에서 VirtualBox 드라이버가 지정되어 있다. VirtualBox 드라이버는 기본 드라이버이므로 다음과 같이 --driver는 생략 할 수도 있다.

PS > docker-machine create devkumahost

실행하면 다음과 같은 로그가 출력된다.

PS C:\> docker-machine create --driver virtualbox devkumahost
Running pre-create checks...
(devkumahost) Image cache directory does not exist, creating it at C:\Users\kimkc\.docker\machine\cache...
(devkumahost) No default Boot2Docker ISO found locally, downloading the latest release...
(devkumahost) Latest release for github.com/boot2docker/boot2docker is v19.03.12
(devkumahost) Downloading C:\Users\kimkc\.docker\machine\cache\boot2docker.iso from https://github.com/boot2docker/boot2docker/releases/download/v19.03.12/boot2docker.iso...
(devkumahost) 0%....10%....20%....30%....40%....50%....60%....70%....80%....90%....100%
Creating machine...
(devkumahost) Copying C:\Users\kimkc\.docker\machine\cache\boot2docker.iso to C:\Users\kimkc\.docker\machine\machines\devkumahost\boot2docker.iso...
(devkumahost) Creating VirtualBox VM...
(devkumahost) Creating SSH key...
(devkumahost) Starting the VM...
(devkumahost) Check network to re-create if needed...
(devkumahost) Windows might ask for the permission to create a network adapter. Sometimes, such confirmation window is minimized in the taskbar.
(devkumahost) Found a new host-only adapter: "VirtualBox Host-Only Ethernet Adapter #2"
(devkumahost) Windows might ask for the permission to configure a network adapter. Sometimes, such confirmation window is minimized in the taskbar.
(devkumahost) Windows might ask for the permission to configure a dhcp server. Sometimes, such confirmation window is minimized in the taskbar.
(devkumahost) Waiting for an IP...
Waiting for machine to be running, this may 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 machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: C:\docker\docker-machine.exe env devkumahost

Boot2Docker 이미지 파일 (boot2docker.iso)을 다운로드하고 있는 것을 확인 할 수 있다. 다운로드한 파일이 저장되어 다음 Docker 호스트를 만들 때 재사용된다.

(devkumahost) Copying C:\Users\kimkc\.docker\machine\cache\boot2docker.iso to C:\Users\kimkc\.docker\machine\machines\devkumahost\boot2docker.iso...
(devkumahost) Creating VirtualBox VM...

이 로그는 다운로드한 Boot2Docker 이미지 파일을 바탕으로 VirtualBox의 가상 머신을 생성하고 있음을 보여준다.

(devkumahost) Creating SSH key...

Docker 호스트에 SSH 연결하는데 필요한 키 쌍을 생성한다. 이 외에도 공개 키를 Docker 호스트의 가상 디스크에 포함 등 SSH 연결에 필요한 설정이 자동으로 이루어진다.

Docker is up and running!

Docker 호스트에서 Docker이 동작하고 있다!

여기까지 create명령을 한 줄만 실행했을 뿐있었다. 시간은 필자의 환경에서는 몇 분밖에 안걸렸다.

정말 Docker 호스트가 만든 여부 확인해 보도록 하자.

PS C:\> docker-machine ls
NAME          ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER      ERRORS
devkumahost   -        virtualbox   Running   tcp://192.168.99.100:2376           v19.03.12

ls명령은 Docker 호스트의 목록을 출력하는 명령이다. “devkumahost” 라는 Docker 호스트가 작성되어 있는 것이 확인 된다. 상태는 “Running"이므로 실행중인 것이다. “v19.03.12"는 이용중인 Docker 버전이다.

Docker 호스트에 로그인

다음은 만든 Docker 호스트에 로그인하여 보자.

로그인은 SSH으로 한다. 이미 SSH에 대한 설정은 자동으로 완료되었기에 다음과 같이 Docker Machine의 ssh 명령에 호스트 이름을 지정하면 로그인 할 수 있다.

PS C:\> docker-machine ssh devkumahost
   ( '>')
  /) TC (\   Core is distributed with ABSOLUTELY NO WARRANTY.
 (/-_--_-\)           www.tinycorelinux.net

docker@devkumahost:~$

이 처럼 Docker Machine을 사용하여 Docker 호스트를 작성하면, SSH에 대해서는 거의 신경쓸 필요는 없다.

Docker 호스트에 Hello World

Docker 호스트에 로그인 할 수 있었고, 다음은 Docker의 동작 확인해 보자.

Docker는 이미 Docker 호스트에 설치되어 즉시 동작하는 상태이다. Docker 호스트에 로그인 한 상태에서 다음과 같이 hello-world 컨테이너를 생성하고 시작하자.

docker@devkumahost:~$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:9f6ad537c5132bcce57f7a0a20e317228d382c3cd61edae14650eec68b2b345c
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

docker@devkumahost:~$

앞중간에 부분에 “Hello from Docker!” 라고 표시가 되었다!

이것으로 create 명령으로 Docker 호스트를 만들고, ssh로 로그인하여 Docker를 사용할 수 있게 되었다.

사실 ssh명령에 로그인하지 않아도 Windows Docker CLI가 있으면 Docker를 사용할 수 있지만, 그 방법은 이후의 다시 소개하도록 하겠다.

다음은 기타 Docker Machine 명령이나 문제가 있을 때 해결 방법을 몇 가지 소개해 보겠다.

Docker 호스트의 기동 · 정지

여기까지 작업을 진행해 왔다면 Docker 호스트 “devkumahost"에 로그인 한 상태라고 생각된다.

우선은 Linux의 exit명령을 실행하여 Docker 호스트에서 로그 아웃한다.

docker@devkumahost:~$ exit
logout
PS C:\>

로그 아웃해도 Docker 호스트 기동되고 있다. status명령으로 상태를 확인하자.

PS C:\> docker-machine status devkumahost
Running

“Running"이므로, 역시 기동되어 있다.

그럼 stop 명령으로 중지해 보자.

PS C:\> docker-machine stop devkumahost
Stopping "devkumahost"...
Machine "devkumahost" was stopped.

정지되었다. status 명령로 다시 확인 하면 “Stopped"이라고 표시된 것을 확인 할수 있다.

PS C:\> docker-machine status devkumahost
Stopped

이어 start명령으로 다시 시작해 보자.

PS C:\> docker-machine start devkumahost
Starting "devkumahost"...
(devkumahost) Check network to re-create if needed...
(devkumahost) Windows might ask for the permission to configure a dhcp server. Sometimes, such confirmation window is minimized in the taskbar.
(devkumahost) Waiting for an IP...
Machine "devkumahost" was started.
Waiting for SSH to be available...
Detecting the provisioner...
Started machines may have new IP addresses. You may need to re-run the `docker-machine env` command.

시작되었다. status 명령로 다시 확인 하면 “Running"이라고 표시된 것을 확인 할수 있다.

PS C:\> docker-machine status devkumahost
Running

stop, start명령 대신 restart명령을 실행하면 중지한 후 다시 시작한다.

PS C:\> docker-machine restart devkumahost
Restarting "devkumahost"...
(devkumahost) Check network to re-create if needed...
(devkumahost) Windows might ask for the permission to configure a dhcp server. Sometimes, such confirmation window is minimized in the taskbar.
(devkumahost) Waiting for an IP...
Waiting for SSH to be available...
Detecting the provisioner...
Restarted machines may have new IP addresses. You may need to re-run the `docker-machine env` command.

Docker 호스트 제거

필요 없게된 Docker 호스트는 rm 명령으로 삭제할 수 있다.

PS C:\> docker-machine rm devkumahost
About to remove devkumahost
WARNING: This action will delete both local reference and remote instance.
Are you sure? (y/n): y
Successfully removed devkumahost

삭제되었는지 확인하려면 ls명령으로 Docker 호스트의 목록을 확인해 보면 된다.

PS C:\> docker-machine ls
NAME   ACTIVE   DRIVER   STATE   URL   SWARM   DOCKER   ERRORS

또는, VirtualBox의 GUI에서 확인해도 된다. 삭제된 Docker 호스트는 표시되지 않을 것이다.

Docker 호스트의 설정 정보

inspect 명령을 실행하면 Docker 호스트의 설정 정보를 JSON 형식으로 출력 할 수 있다.

PS C:\> docker-machine inspect devkumahost
{
    "ConfigVersion": 3,
    "Driver": {
        "IPAddress": "192.168.99.102",
        "MachineName": "devkumahost",
        "SSHUser": "docker",
        "SSHPort": 2644,
        (이하 생략)         

또한, 다음 폴더에 설정 파일이 저장되어 있으며, 텍스트 편집기 등으로 열어서 볼 수 있다.

<사용자 홈 디렉터리>\ .docker\machine\ machines\< 호스트 이름>\ config.json

Boot2Docker 버전을 지정

Docker Machine은 특히 아무것도 지정하지 않으면 최신 Boot2Docker 이미지 파일을 다운로드하여 사용할 수 있게 된다.

특정 버전의 Boot2Docker을 이용하고 싶은 경우에는 --virtualbox-boot2docker-url에 이미지 파일의 URL을 지정한다.

PS C:\> docker-machine create --virtualbox-boot2docker-url https://github.com/boot2docker/boot2docker/releases/download/v19.03.12-ce/boot2docker.isl devkumahost1903
Running pre-create checks...
(devkumahost1903) Boot2Docker URL was explicitly set to "https://github.com/boot2docker/boot2docker/releases/download/v19.03.12-ce/boot2docker.isl" at create time, so Docker Machine cannot upgrade this machine to the latest version.
Creating machine...
(devkumahost1903) Boot2Docker URL was explicitly set to "https://github.com/boot2docker/boot2docker/releases/download/v19.03.12-ce/boot2docker.isl" at create time, so Docker Machine cannot upgrade this machine to the latest version.
(devkumahost1903) Downloading C:\Users\kimkc\.docker\machine\cache\boot2docker.iso from https://github.com/boot2docker/boot2docker/releases/download/v19.03.12-ce/boot2docker.isl...
(devkumahost1903)
(devkumahost1903) Creating VirtualBox VM...
(devkumahost1903) Creating SSH key...
Error creating machine: Error in driver during machine creation: C:\Program Files\Oracle\VirtualBox\VBoxManage.exe storageattach devkumahost1903 --storagectl SATA --port 0 --device 0 --type dvddrive --medium C:\Users\kimkc\.docker\machine\machines\devkumahost1903\boot2docker.iso failed:
VBoxManage.exe: error: Could not get the storage format of the medium 'C:\Users\kimkc\.docker\machine\machines\devkumahost1903\boot2docker.iso' (VERR_NOT_SUPPORTED)
VBoxManage.exe: error: Details: code VBOX_E_IPRT_ERROR (0x80bb0005), component MediumWrap, interface IMedium, callee IUnknown
VBoxManage.exe: error: Context: "OpenMedium(Bstr(pszFilenameOrUuid).raw(), enmDevType, enmAccessMode, fForceNewUuidOnOpen, pMedium.asOutParam())" at line 191 of file VBoxManageDisk.cpp
VBoxManage.exe: error: Invalid UUID or filename "C:\Users\kimkc\.docker\machine\machines\devkumahost1903\boot2docker.iso"

여기서 에러가 나는데… 나주엥 찾아보겠다.ㅜㅜ

Docker 호스트 명령의 실행

ssh명령은 인수 Docker 호스트 명령을 사용하여 수행 할 수 있다. 별도 로그인 로그 아웃 명령을 입력 할 필요가 없습니다. OpenSSH 등의 SSH 클라이언트에도 같은 기능이 있군요.

다음 예제에서는 “devkumahost"에 ls 명령을 실행하여 /home디렉터리의 내용을 표시하고 있다.

PS C:\> docker-machine ssh devkumahost ls /home
docker
dockremap
PS C:\>

Docker 호스트에 프록시 정보를 설정

방금 전의 hello-world를 실행하면 다음과 같은 오류가 나타날 수 있다.

docker@devkumahost:~$ docker run hello-world
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get https://registry-1.docker.io/v2/: dial tcp: lookup registry-1.docker.io on 10.0.2.3:53: no such host.
See 'docker run --help'.

원인의 하나로서, 회사나 학교의 HTTP 프록시를 통과할 수 없어서 일 수 있다. 이런 경우 Docker 호스트에 프록시 정보를 설정한다.

프록시 정보는 create명령의 옵션으로 설정할 수 있다.

PS> $http_proxy = 'https://myproxy.com:1234'
PS> $https_proxy = 'https://myproxy.com:1234'
PS> docker-machine create --engine-env HTTP_PROXY=$http_proxy --engine-env HTTPS_PROXY=$https_proxy myhost

$http_proxy$https_proxy은 PowerShell 변수이다. --engine-env는 Docker가 참조하는 환경 변수를 지정하는 옵션으로 “변수이름=값” 형식으로 설정한다.

사용자 이름과 암호가 필요한 경우는 다음과 같이 설정한다.

PS> $http_proxy = 'https://user:password@myproxy.com:1234'
PS> $https_proxy = 'https://user:password@myproxy.com:1234'
PS> docker-machine create --engine-env HTTP_PROXY=$http_proxy --engine-env HTTPS_PROXY=$https_proxy myhost

이 사용자 이름과 암호는 방금 전의 inspect명령을 사용하면 일반 텍스트로 보이므로 있으므로 주의가 필요하다. 또한 Docker Machine 설정 파일(config.json)에 일반 텍스트로 저장된다. GitHub에 개선 요구가 높아지고 있지만 아직까지 지원되지 않는다.

기본 호스트 이름 “default”

Docker 호스트의 이름은 “default"라는 이름에 설정해 두면 편리하다. 일부 명령은 호스트 이름을 생략 할 수 있기 때문이다.

예를 들어, docker-machine start라는 식으로 호스트 이름을 지정하지 않고 start명령을 실행하면 “default"라는 Docker 호스트를 시작하게 된다. 마찬가지로 docker-machine stop는 “default"라는 Docker 호스트를 중지하게 된다.

도움말

이상 소개 한 이외에도 Docker Machine은 다양한 명령과 옵션을 제공한다. 다음 명령으로 도움말이 표시되기에 여러가지 연습해 보면 좋을 것이다.

PS C:\> docker-machine
Usage: docker-machine.exe [OPTIONS] COMMAND [arg...]

(중간 생략)

Commands:
  active                Print which machine is active
  config                Print the connection config for machine
  create                Create a machine
  env                   Display the commands to set up the environment for the Docker client
  inspect               Inspect information about a machine
  ip                    Get the IP address of a machine

(이하 생략)
PS C:\> docker-machine create
Usage: docker-machine create [OPTIONS] [arg...]

(중간 생략)

Options:

   --driver, -d "virtualbox"                                                                            Driver to create machine with. [$MACHINE_DRIVER]
   --engine-env [--engine-env option --engine-env option]                                               Specify environment variables to set in the engine
   --engine-insecure-registry [--engine-insecure-registry option --engine-insecure-registry option]     Specify insecure registries to allow with the created engine
 (이하 생략)

결론 : Docker Machine과 관련 도구

본 기사에서는 Docker Machine을 사용하여 Windows에 Docker 호스트를 만드는 방법을 소개하였다.

Docker Machine 이외에도 Docker 회사에서는 다양한 도구를 개발하고 있다. 다음 조금 긴하지만, 그 도구 중 Docker Machine은 도대체 어떤 자리 매김에 있는지 보면서, 정리해 보도록 하겠다.

다음은 Docker Machine 관련 도구와 출판 년도(괄호)를 보여준다.

  • Boot2Docker (2013)
  • Docker Compose (Fig) (2014)
  • Kitematic (2014)
  • Docker Machine (2014)
  • Docker Toolbox (2015)
  • Docker for Windows (2016)
  • InfraKit (2016)
  • LinuxKit (2017)

Docker가 발표된 것은 2013년 3월이다. 얼마 지나지 않아, Docker사 밖에서 다양한 도구가 개발되어 갔다. Docker사는 그러한 도구를 적극적으로 자사에 가져왔다.

Docker Compose를 사용하여 여러 컨테이너 배포“에서 소개한 Docker Compose는 원래 Fig라는 이름으로 영국의 시작이 개발한 도구였지만, 곧 Docker 사에 인수되었다 .

Kitematic는 GUI에서 Docker를 조작하는 도구이다. 2015년에 이것도 Docker 사에 인수되었다.

그러던 중 2014년 12월 DockerCon EU에서 Docker Machine이 발표되었다. 이미 설명했듯이 Docker Machine은 Boot2Docker의 성과를 발전시킨 도구이다.

Docker Toolbox는 Windows와 Mac에서도 Docker를 쉽게 사용할 수 있도록 하자는 도구이다. 내용은 Docker Compose, Kitematic, Docker Machine 등을 한 패키지로 한 것이다. 말하자면 Docker 사가 해왔던 개발 도구의 집대성이라고도 말할 수 있는 도구였던 셈이다.

여기에서 사람 구분이 새로운 흐름이 시작된 것 같은 느낌을 받는다.

다음 Docker for Windows는 Toolbox와 마찬가지로 Windows에서도 Docker를 쉽게 사용할 수 있도록 하자는 도구이다. 그러나 Docker for Windows는 Docker 호스트를 작성하는 방법으로 기본적으로 Docker Machine을 사용하지 않는다. Docker Machine은 클러스터 환경을 만드는 경우 등 필요한 경우 사용 도구는 평가한다. 가상 환경 도구도 VirtualBox 대신 Hyper-V를 채택하고 있다.

InfraKit과 LinuxKit는 Docker 호스트의 작성 · 관리 및 이미지 파일을 만들 도구이다. Docker Machine보다 강력하고, Boot2Docker보다 유연하게 커스터마이즈할 수 있는 도구라고 해도 좋을 것이다. 이는 단적으로 나타내고 있는 것이 다음 Docker Machine의 GitHub 저장소의 코멘트이다. 모두 Docker 사의 개발자의 코멘트이다.

댓글 1 :

We have introduced more focused projects such as infrakit for multi host production deployments, linuxkit for a maintainable and extensible replacement for boot2docker

댓글 2 :

On the other hand, while we still want to maintain the project and make sure the people using it today can continue to do so as long as it is useful, we will not be adding any new feature to the project from here onward

즉, Docker사로는 향후 InfraKit과 LinuxKit에 주력해 나갈, Docker Machine은 계속 유지하고 가지만 새로운 기능은 추가하지 않는다는 것이다. 이 정책은 아직 공식적으로 발표 된 것은 없다. 또한 Docker Machine은 오픈 소스 소프트웨어이기 때문에 유지가 포크하고 기능을 추가하는 것을 계속할지도 모른다. 그러나 Docker Machine이 지금 큰 기로에 서있는 것은 틀림 없을 것이다.

지금까지 필자 개인적으로는 Docker에 아직 익숙하지 않은 분은 먼저 Docker Machine을 이용하는 것이 좋다고 생각한다. Docker for Windows와 같은 GUI 도구는 좋든 나쁘든 내부 구조가 보이지 어려운 도구이다. Docker Machine을 사용한 경험이 있으면 Docker for Windows가 대략 무엇을 해주는 도구인지 이해하기 쉽고, Docker를 잘 다룰 수 있게되는 것도 빠른 것이다.

본 기사에서 소개 한대로 Docker Machine은 간편하게 사용할 수있는 도구이다. Docker을 효율적으로 이해하고 다룰 수 있게 되기 위해서도 Docker Machine을 만져 보면 좋을 것이다.




최종 수정 : 2021-07-01