25
24

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Docker Machine を使って DigitalOcean に Dockerホストを立てる

Last updated at Posted at 2015-02-28

概要

Docker公式オーケストレーションツールの 1 つ Docker Machine を使って DigitalOcean に Docker がインストールされた Droplet を作成し、hello world を出力するコンテナを走らせてみるという話

必要なもの

  • Access Tokens (Writable)

_2015-02-28_12_25_33

_2015-02-28_12_26_53

_2015-02-28_12_27_44

_2015-02-28_12_28_34

Hello World

docker-machine create コマンドで Dockerホストを作成する。

(token はダミー)

$ docker-machine create \
    --driver digitalocean \
    --digitalocean-access-token 
    f851029140a409712047b22d4c2696277af113d02feebf5477fb27 \
    staging
INFO[0000] Creating SSH key...
INFO[0002] Creating Digital Ocean droplet...
INFO[0005] Waiting for SSH...
INFO[0074] Configuring Machine...
INFO[0141] "staging" has been created and is now the active machine.
INFO[0141] To point your Docker client at it, run this in your shell: $(docker-machine env staging)

マシンリストを見てみる

$ docker-machine ls
NAME      ACTIVE   DRIVER         STATE     URL                          SWARM
dev                virtualbox     Running   tcp://192.168.99.100:2376
staging   *        digitalocean   Running   tcp://104.236.194.241:2376

SSH ログイン

$ docker-machine ssh staging
Welcome to Ubuntu 14.04.1 LTS (GNU/Linux 3.13.0-43-generic x86_64)

 * Documentation:  https://help.ubuntu.com/

  System information as of Fri Feb 27 22:33:28 EST 2015

  System load:  0.25               Processes:              70
  Usage of /:   11.4% of 19.56GB   Users logged in:        0
  Memory usage: 12%                IP address for eth0:    104.236.194.241
  Swap usage:   0%                 IP address for docker0: 172.17.42.1

  Graph this data and manage this system at:
    https://landscape.canonical.com/

root@staging:~#

SSH 経由でのコマンド実行

$ docker-machine ssh staging "hostname && uname -a"
staging
Linux staging 3.13.0-43-generic #72-Ubuntu SMP Mon Dec 8 19:35:06 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

マシンのストップ

$ docker-machine stop staging
$ docker-machine ls
NAME      ACTIVE   DRIVER         STATE     URL                          SWARM
dev                virtualbox     Running   tcp://192.168.99.100:2376
staging   *        digitalocean   Stopped   tcp://104.236.194.241:2376
# DO 上では => Droplet が Status Off になっている

マシンのスタート

$ docker-machine start staging
$ docker-machine ls
NAME      ACTIVE   DRIVER         STATE     URL                          SWARM
dev                virtualbox     Running   tcp://192.168.99.100:2376
staging   *        digitalocean   Running   tcp://104.236.194.241:2376

Hello World

$ docker $(docker-machine config staging) run busybox echo hello world
Unable to find image 'busybox' locally
511136ea3c5a: Pull complete
df7546f9f060: Pull complete
ea13149945cb: Pull complete
4986bf8c1536: Pull complete
busybox:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security.

Status: Downloaded newer image for busybox:latest
hello world
$ docker $(docker-machine config staging) ps -a
CONTAINER ID        IMAGE               COMMAND              CREATED             STATUS                     PORTS               NAMES
fd02ad4af931        busybox:latest      "echo hello world"   8 seconds ago       Exited (0) 6 seconds ago                       reverent_pasteur

マシンの削除

$ docker-machine rm staging
$ docker-machine ls
NAME   ACTIVE   DRIVER       STATE     URL                         SWARM
dev             virtualbox   Running   tcp://192.168.99.100:2376

REF

25
24
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
25
24

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?