Docker

  • 投稿者:
  • 投稿カテゴリー:docker

2015-07-02_214621

概要

http://dotinstall.com/lessons/basic_docker
のまとめ。このメモ見るなら本家見たほうがよいです

Dockerとは

・軽量な仮想化環境を作るツール
・Ubuntuにて開発されている

root@ubuntu:/home/shimizu# wget -qO- https://get.docker.com/ | sh
...
The following NEW packages will be installed:
  crda iw libnl-3-200 libnl-genl-3-200 linux-image-3.13.0-55-generic
  linux-image-extra-3.13.0-55-generic linux-image-extra-3.16.0-40-generic
  linux-image-extra-virtual linux-image-generic wireless-regdb
0 upgraded, 10 newly installed, 0 to remove and 32 not upgraded.
Need to get 89.5 MB of archives.
...

root@ubuntu:/home/shimizu# docker -v
Docker version 1.7.0, build 0baf609

イメージ

2015-07-02_223317
Docker Index:Imageの共有サイト
Imageをダウンロード(docker pull)して、Containerとして実行する(docker run)
Containerを別のDockerサーバに移動させるには、ContainerをImageに変換(docker commit)して
Docker Indexに登録する(docker push)

操作方法

### Imageのダウンロード ###
root@ubuntu:/home/shimizu# docker search centos
NAME                          DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
centos                        The official build of CentOS.                   1092      [OK]
tutum/centos                  Centos image with SSH access. For the root...   13                   [OK]
blalor/centos                 Bare-bones base CentOS 6.5 image                9                    [OK]
torusware/speedus-centos      Always updated official CentOS docker imag...   6                    [OK]
million12/centos-supervisor   Base CentOS-7 with supervisord launcher, h...   5                    [OK]
jdeathe/centos-ssh            CentOS-6 6.6 x86_64 / EPEL Repo. / OpenSSH...   3                    [OK]
layerworx/centos              A general CentOS 6 image with the EPEL6 an...   2                    [OK]
jdeathe/centos-ssh-mysql      CentOS-6 6.6 x86_64 / MySQL.                    2                    [OK]
pdericson/centos              Docker image for CentOS                         0                    [OK]
nathonfowlie/centos-jre       Latest CentOS image with the JRE pre-insta...   0                    [OK]

root@ubuntu:/home/shimizu# docker pull centos
latest: Pulling from centos
f1b10cd84249: Pull complete
c852f6d61e65: Pull complete
7322fbe74aa5: Already exists
centos: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.
Digest: sha256:a4627c43bafc86705af2e8a5ea1f0ed34fbf27b6e7a392e5ee45dbd4736627cc
Status: Downloaded newer image for centos:latest

root@ubuntu:/home/shimizu# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos              latest              7322fbe74aa5        13 days ago         172.2 MB

# 詳細を表示する。IDについては一意であれば何文字でもOK
root@ubuntu:/home/shimizu# docker inspect 73 
...

### Containerを作成する ###
root@ubuntu:/home/shimizu# docker run 73 echo "hello world"
hello world

# 実行が完了したプロセスを表示する
root@ubuntu:/home/shimizu# docker ps -a
CONTAINER ID        IMAGE               COMMAND                CREATED              STATUS                          PORTS               NAMES
6d654c9581e3        73                  "echo 'hello world'"   About a minute ago   Exited (0) About a minute ago                       sharp_kirch

root@ubuntu:/home/shimizu# docker run -d centos free -s 3
29c3e9f265781ab94817e1c8ca2f54bf26d243ad702db0acd1f2631c4332a283

# 実行中のプロセスを表示する
root@ubuntu:/home/shimizu# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
29c3e9f26578        centos              "free -s 3"         2 seconds ago       Up 1 seconds                            hungry_jones

root@ubuntu:/home/shimizu# docker logs 29c3e9f26578
              total        used        free      shared  buff/cache   available
Mem:         686628       84136      107884         452      494608      474308
Swap:             0           0           0

              total        used        free      shared  buff/cache   available
Mem:         686628       81572      110440         460      494616      476900
Swap:             0           0           0

              total        used        free      shared  buff/cache   available
Mem:         686628       81572      110440         460      494616      476900
Swap:             0           0           0

              total        used        free      shared  buff/cache   available
Mem:         686628       81560      110440         460      494628      476900
Swap:             0           0           0

              total        used        free      shared  buff/cache   available
Mem:         686628       81560      110440         460      494628      476912
Swap:             0           0           0

root@ubuntu:/home/shimizu# docker kill 29c3e9f26578
29c3e9f26578

root@ubuntu:/home/shimizu# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

### ContainerからImageを作成して、正しく動作するか確認する ###
root@ubuntu:/home/shimizu# docker run -i -t centos /bin/bash
[root@ff4b98c69eb6 /]# touch hello.txt
[root@ff4b98c69eb6 /]# ls
bin  dev  etc  hello.txt  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
[root@ff4b98c69eb6 /]# exit

root@ubuntu:/home/shimizu# docker ps -a
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS                       PORTS               NAMES
ff4b98c69eb6        centos              "/bin/bash"            25 seconds ago      Exited (0) 9 seconds ago                         hopeful_pike                    

root@ubuntu:/home/shimizu# docker commit ff4 test/hello
8fac9b012f2d1983a9bd10ad5f1e48ab270b9603963dff46dd22be777ccdb04f

root@ubuntu:/home/shimizu# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
test/hello          latest              8fac9b012f2d        9 seconds ago       172.2 MB
centos              latest              7322fbe74aa5        13 days ago         172.2 MB

root@ubuntu:/home/shimizu# docker run -i -t test/hello /bin/bash
[root@33f4291501ed /]# ls
bin  dev  etc  hello.txt  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var