dockerを勉強するために色々いじってみたときの作業ログ

# yum -y install docker-io
# service docker start
Starting cgconfig service:                                 [  OK  ]
Starting docker:                                       [  OK  ]
# chkconfig docker on
  • dockerの情報
# docker -v
Docker version 0.11.1, build fb99f99/0.11.1
# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
# docker info
Containers: 0
Images: 0
Storage Driver: devicemapper
 Pool Name: docker-253:0-789041-pool
 Data file: /var/lib/docker/devicemapper/devicemapper/data
 Metadata file: /var/lib/docker/devicemapper/devicemapper/metadata
 Data Space Used: 291.5 Mb
 Data Space Total: 102400.0 Mb
 Metadata Space Used: 0.7 Mb
 Metadata Space Total: 2048.0 Mb
Execution Driver: lxc-0.9.0
Kernel Version: 2.6.32-431.17.1.el6.x86_64
# docker version
Client version: 0.11.1
Client API version: 1.11
Go version (client): go1.2.1
Git commit (client): fb99f99/0.11.1
Server version: 0.11.1
Server API version: 1.11
Git commit (server): fb99f99/0.11.1
Go version (server): go1.2.1
Last stable version: 1.0.0, please update docker
  • ディスクの状況とか
$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_mpon-lv_root
                       16G  1.6G   13G  11% /
tmpfs                 939M     0  939M   0% /dev/shm
/dev/sda1             485M   84M  376M  19% /boot
  • rootじゃないとなんかダメ
$ docker info
2014/06/12 13:15:06 Get http:///var/run/docker.sock/v1.11/info: dial unix /var/run/docker.sock: permission denied
  • プロキシの設定
$ sudo vim /etc/sysconfig/docker
export http_proxy=http://example.com
  • pullするとimageができる。容量も小さい。すぐダウンロードできた
$ sudo docker pull centos:latest
Pulling repository centos
0c752394b855: Download complete
511136ea3c5a: Download complete
34e94e67e63a: Download complete
$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_mpon-lv_root
                       16G  1.8G   13G  12% /
tmpfs                 939M     0  939M   0% /dev/shm
/dev/sda1             485M   84M  376M  19% /boot
$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos              latest              0c752394b855        2 days ago          124.1 MB
$ sudo docker info
Containers: 0
Images: 3
Storage Driver: devicemapper
 Pool Name: docker-253:0-789041-pool
 Data file: /var/lib/docker/devicemapper/devicemapper/data
 Metadata file: /var/lib/docker/devicemapper/devicemapper/metadata
 Data Space Used: 455.2 Mb
 Data Space Total: 102400.0 Mb
 Metadata Space Used: 0.8 Mb
 Metadata Space Total: 2048.0 Mb
Execution Driver: lxc-0.9.0
Kernel Version: 2.6.32-431.17.1.el6.x86_64
  • runしてみた。imageが増えたりはしない
$ sudo docker run -i -t centos cat /etc/redhat-release
CentOS release 6.5 (Final)
$ sudo docker run -i -t centos whoami
root
$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS                      PORTS               NAMES
ab3ac496b2d1        centos:latest       whoami                 23 seconds ago      Exited (0) 22 seconds ago                       stupefied_meitner
de3b79315a19        centos:latest       cat /etc/redhat-rele   48 seconds ago      Exited (0) 46 seconds ago                       distracted_lovelace

$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos              latest              0c752394b855        2 days ago          124.1 MB
  • コンテナ消してみる
$ sudo docker rm ab3ac496b2d1
ab3ac496b2d1
$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS                     PORTS               NAMES
de3b79315a19        centos:latest       cat /etc/redhat-rele   4 minutes ago       Exited (0) 4 minutes ago                       distracted_lovelace
  • ubuntu pullしてみる。これもサイズ小さい。
$ sudo docker pull ubuntu:latest
Pulling repository ubuntu
ad892dd21d60: Download complete
511136ea3c5a: Download complete
e465fff03bce: Download complete
23f361102fae: Download complete
9db365ecbcbb: Download complete
$ df
Filesystem           1K-blocks    Used Available Use% Mounted on
/dev/mapper/vg_mpon-lv_root
                      16070076 2124904  13128840  14% /
tmpfs                   961012       0    961012   0% /dev/shm
/dev/sda1               495844   85633    384611  19% /boot
$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos              latest              0c752394b855        2 days ago          124.1 MB
ubuntu              latest              ad892dd21d60        7 days ago          275.4 MB
$ sudo docker run -i -t ubuntu /bin/bash
root@348c761db595:/# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04 LTS"
root@348c761db595:/# arch
x86_64
root@348c761db595:/# df -h
Filesystem                                                                                        Size  Used Avail Use% Mounted on
/dev/mapper/docker-253:0-789041-348c761db595d47d05cdbf6b4a02ae71a2847e1688be1125f7a0b68e06481fd8  9.9G  415M  9.0G   5% /
shm                                                                                                64M     0   64M   0% /dev/shm
/dev/mapper/vg_mpon-lv_root                                                                         16G  2.1G   13G  14% /etc/hosts
root@348c761db595:/# whoami
root
root@348c761db595:/# ll /
bash: ll: command not found
root@348c761db595:/# ls /
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
root@348c761db595:/# ls /home/
root@348c761db595:/# exit
exit
  • CentOSのimageの中もどうなってるか見てみた
$ sudo docker run -i -t centos /bin/bash
bash-4.1# cat /etc/redhat-release
CentOS release 6.5 (Final)
bash-4.1# uname -a
Linux 1ff5261cd564 2.6.32-431.17.1.el6.x86_64 #1 SMP Wed May 7 23:32:49 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
bash-4.1# df -h
Filesystem            Size  Used Avail Use% Mounted on
rootfs                9.9G  294M  9.1G   4% /
/dev/mapper/docker-253:0-789041-1ff5261cd564ab86f4f05e5f3f87a1b77f2d047dcaa69d0160b0882d19f5d49b
                      9.9G  294M  9.1G   4% /
shm                    64M     0   64M   0% /dev/shm
/dev/mapper/vg_mpon-lv_root
                       16G  2.1G   13G  14% /.dockerinit
/dev/mapper/vg_mpon-lv_root
                       16G  2.1G   13G  14% /etc/resolv.conf
/dev/mapper/vg_mpon-lv_root
                       16G  2.1G   13G  14% /etc/hostname
/dev/mapper/vg_mpon-lv_root
                       16G  2.1G   13G  14% /etc/hosts
/dev/mapper/vg_mpon-lv_root
                       16G  2.1G   13G  14% /.dockerenv
bash-4.1# ls /
bin  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  sbin  selinux  srv  sys  tmp  usr  var
bash-4.1# ls /home/
bash-4.1# whoami
root
bash-4.1# exit
exit
  • このときのコンテナの様子
$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                          PORTS               NAMES
1ff5261cd564        centos:latest       /bin/bash           53 seconds ago      Exited (0) 11 seconds ago                           evil_rosalind
348c761db595        ubuntu:latest       /bin/bash           3 minutes ago       Exited (0) About a minute ago                       compassionate_pasteur
  • mysqlおとしてみる。でかい。色々なバージョンが含まれてる?
$ sudo docker pull mysql
Pulling repository mysql
01e690393148: Download complete
511136ea3c5a: Download complete
1e8abad02296: Download complete
f106b5d7508a: Download complete
bd80da5e6905: Download complete
b0404087597a: Download complete
028f7f1b8257: Download complete
28a9095ddeec: Download complete
962a51a47c07: Download complete
1e880d86b89a: Download complete
43e7b3d62821: Download complete
27379a1edc3e: Download complete
8a66c5d6b873: Download complete
d63852d42362: Download complete
534b33bb70be: Download complete
898f9824cadc: Download complete
44214af1f053: Download complete
11a657552061: Download complete
$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos              latest              0c752394b855        2 days ago          124.1 MB
ubuntu              latest              ad892dd21d60        7 days ago          275.4 MB
mysql               5                   01e690393148        7 days ago          3.621 GB
mysql               5.6                 01e690393148        7 days ago          3.621 GB
mysql               5.6.17              01e690393148        7 days ago          3.621 GB
mysql               latest              01e690393148        7 days ago          3.621 GB
$ df
Filesystem           1K-blocks    Used Available Use% Mounted on
/dev/mapper/vg_mpon-lv_root
                      16070076 5860340   9393404  39% /
tmpfs                   961012       0    961012   0% /dev/shm
/dev/sda1               495844   85633    384611  19% /boot
  • mysql起動してみた
$ sudo docker run --name sample -e MYSQL_ROOT_PASSWORD=password -d mysql
31eae8d0294fb44255b84568afbfe1c59e4acd0d1bce9ef3fc2acede1807d8a3
$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS                      PORTS               NAMES
31eae8d0294f        mysql:5             /entrypoint.sh mysql   26 seconds ago      Up 26 seconds               3306/tcp            sample
1ff5261cd564        centos:latest       /bin/bash              15 minutes ago      Exited (0) 15 minutes ago                       evil_rosalind
348c761db595        ubuntu:latest       /bin/bash              18 minutes ago      Exited (0) 16 minutes ago                       compassionate_pasteur
  • 一体何が起きた?プロセスは起動してるっぽい
$ ps aux | grep mysql
root      3032  0.0  0.0  18904  1152 ?        Ss   14:10   0:00 lxc-start -n 31eae8d0294fb44255b84568afbfe1c59e4acd0d1bce9ef3fc2acede1807d8a3 -f /var/lib/docker/containers/31eae8d0294fb44255b84568afbfe1c59e4acd0d1bce9ef3fc2acede1807d8a3/config.lxc -- /.dockerinit -driver lxc -g 172.17.42.1 -i 172.17.0.2/16 -mtu 1500 -w /usr/local/mysql -- /entrypoint.sh mysqld --datadir=/var/lib/mysql --user=mysql
999       3038  0.4  5.7 736836 109896 ?       Sl   14:10   0:00 mysqld --datadir=/var/lib/mysql --user=mysql --init-file=/tmp/mysql-first-time.sql
500       3181  0.0  0.0 107460   916 pts/0    S+   14:13   0:00 grep mysql
  • mysqlログインしてみる
$ sudo docker run -it --link sample:mysql --rm mysql sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"'
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.17 Source distribution

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.01 sec)

mysql>
$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND                CREATED              STATUS                      PORTS               NAMES
7084556078bb        mysql:5             "/entrypoint.sh sh -   About a minute ago                                                   silly_almeida
31eae8d0294f        mysql:5             /entrypoint.sh mysql   22 minutes ago       Up 22 minutes               3306/tcp            sample
1ff5261cd564        centos:latest       /bin/bash              38 minutes ago       Exited (0) 37 minutes ago                       evil_rosalind
348c761db595        ubuntu:latest       /bin/bash              40 minutes ago       Exited (0) 38 minutes ago                       compassionate_pasteur
$ sudo docker run -i -t mysql /bin/bash
root@0e32ab7457cd:/usr/local/mysql# ls /
bin  boot  dev  entrypoint.sh  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
root@0e32ab7457cd:/usr/local/mysql# aarch
bash: aarch: command not found
root@0e32ab7457cd:/usr/local/mysql# arch
x86_64
root@0e32ab7457cd:/usr/local/mysql# ls /home/
root@0e32ab7457cd:/usr/local/mysql# pwd
/usr/local/mysql
root@0e32ab7457cd:/usr/local/mysql# whoami
root
root@0e32ab7457cd:/usr/local/mysql# which mysql
/usr/local/mysql/bin/mysql
root@0e32ab7457cd:/usr/local/mysql# ls
COPYING  INSTALL-BINARY  README  bin  data  docs  include  lib  man  mysql-test  scripts  share  sql-bench  support-files
root@0e32ab7457cd:/usr/local/mysql# cd
root@0e32ab7457cd:/# pwd
/
root@0e32ab7457cd:/# df -h
Filesystem                                                                                        Size  Used Avail Use% Mounted on
/dev/mapper/docker-253:0-789041-0e32ab7457cd34437c6ca6adfa2563ae6ad316fadac621e6a16b59d8033887c8  9.9G  3.6G  5.8G  39% /
shm                                                                                                64M     0   64M   0% /dev/shm
/dev/mapper/vg_mpon-lv_root                                                                         16G  5.8G  8.9G  40% /etc/hosts
root@0e32ab7457cd:/# uname -a
Linux 0e32ab7457cd 2.6.32-431.17.1.el6.x86_64 #1 SMP Wed May 7 23:32:49 UTC 2014 x86_64 GNU/Linux
root@0e32ab7457cd:/# cat /proc/version
Linux version 2.6.32-431.17.1.el6.x86_64 (mockbuild@c6b8.bsys.dev.centos.org) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC) ) #1 SMP Wed May 7 23:32:49 UTC 2014
root@0e32ab7457cd:/# which yum
root@0e32ab7457cd:/# which apt-get
/usr/bin/apt-get
root@0e32ab7457cd:/# cat /etc/de
debconf.conf    debian_version  default/
root@0e32ab7457cd:/# cat /etc/debian_version
jessie/sid
root@0e32ab7457cd:/#
  • コンテナ消そうとしたら怒られた
$ sudo docker rm 31eae8d0294f
Error: Impossible to remove a running container, please stop it first or use -f
2014/06/12 15:03:13 Error: failed to remove one or more containers
$ sudo docker stop 31eae8d0294f
31eae8d0294f
$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS                         PORTS               NAMES
31eae8d0294f        mysql:5             /entrypoint.sh mysql   53 minutes ago      Exited (0) 7 seconds ago                           sample
1ff5261cd564        centos:latest       /bin/bash              About an hour ago   Exited (0) About an hour ago                       evil_rosalind
348c761db595        ubuntu:latest       /bin/bash              About an hour ago   Exited (0) About an hour ago                       compassionate_pasteur
  • -dというのがデーモンとしてMySQLを起動するみたいな感じかな。

  • mysqlのimage消した

$ sudo docker rmi 01e690393148
Untagged: mysql:5
Untagged: mysql:5.6
Untagged: mysql:5.6.17
Untagged: mysql:latest
Deleted: 01e690393148fd2dd42701f917d4fe297dc9e14e405178377a87759fbd65c206
Deleted: 11a65755206163698ef1bd66e862893ce5c4dc92d3ca589726685dde77b6bb04
Deleted: 44214af1f05325d116cc3ad6a29ae662b1e7ab53a342f4dabccbd42a0a5b2c29
Deleted: 898f9824cadc886a1a4737fbe720440fc5daedd8ec8336f12977de73067135ee
Deleted: 534b33bb70be905bd26680539180ee7019f28ab6b9f504aee8eb1f9be213bc8d
Deleted: d63852d4236229e0eb16f45e11fd2bc430e0c143f44085f35dba2399f6aa48bb
Deleted: 8a66c5d6b873bf6e6328c87365432380b0f536221683ea7ac0cf669e91576923
Deleted: 27379a1edc3eeb57b0a290d846340f2a46f7cc895de82c0aeac49aec3b3a3d0c
Deleted: 43e7b3d628219f575d68531b7dae656d02e0f7591ab286d8f8e75884c698b7b2
Deleted: 1e880d86b89a7e37fa3ad8bb7c90e3f1e217d1929bbac3b582c22ab5a41dea28
Deleted: 962a51a47c07663e3fe52dcd6cee3fd89fa317585882b7cc89dd0a0b591547e7
Deleted: 28a9095ddeec010ad3bfc14c63ec3bd092f852f7913a75726a8ef70ae6b13ef1
Deleted: 028f7f1b82576b60173f7578faecaed2f471638fadfbc8af4f18f4b383f36604
Deleted: b0404087597a06500af2a1b5fdbb671ae6d35927df6efee63a4fc85427a43ed6
Deleted: bd80da5e6905bc21119565c7d799f7bcc12866306e398f859c3b30449827e8a7
Deleted: f106b5d7508a201e2501078bb96d877cf50cf0b799242bea90aba294fa9539ac
Deleted: 1e8abad02296ab9c600564b43d4f3e34855cfd40433f32e2ba90aaab37b07f7d
$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos              latest              0c752394b855        2 days ago          124.1 MB
ubuntu              latest              ad892dd21d60        7 days ago          275.4 MB
$ df
Filesystem           1K-blocks    Used Available Use% Mounted on
/dev/mapper/vg_mpon-lv_root
                      16070076 2244836  13008908  15% /
tmpfs                   961012       0    961012   0% /dev/shm
/dev/sda1               495844   85633    384611  19% /boot
  • viすらないからCentOSvimをインストール。ほんとに何もはいってないんだな。
bash-4.1# yum install vim
略
=========================================================================================================================
 Package                              Arch                  Version                            Repository           Size
=========================================================================================================================
Installing:
 vim-enhanced                         x86_64                2:7.2.411-1.8.el6                  base                892 k
Installing for dependencies:
 gpm-libs                             x86_64                1.20.6-12.el6                      base                 28 k
 perl                                 x86_64                4:5.10.1-136.el6                   base                 10 M
 perl-Module-Pluggable                x86_64                1:3.90-136.el6                     base                 40 k
 perl-Pod-Escapes                     x86_64                1:1.04-136.el6                     base                 32 k
 perl-Pod-Simple                      x86_64                1:3.13-136.el6                     base                212 k
 perl-libs                            x86_64                4:5.10.1-136.el6                   base                578 k
 perl-version                         x86_64                3:0.77-136.el6                     base                 51 k
 vim-common                           x86_64                2:7.2.411-1.8.el6                  base                6.0 M
 which                                x86_64                2.19-6.el6                         base                 38 k

Transaction Summary
=========================================================================================================================
Install      10 Package(s)
略
  • vimをインストールしたコンテナをコミットしてみる
$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
c0cdfd5b287e        centos:latest       /bin/bash           2 hours ago         Exited (0) 7 seconds ago                       furious_pare
$ sudo docker commit c0cdfd5b287e mp/kandan
2014/06/12 20:01:07 Invalid namespace name (mp), only [a-z0-9_] are allowed, size between 4 and 30
$ sudo docker commit c0cdfd5b287e mpon/kandan
6cffc5599b7e75839128308e73d75ed1846fdeda45ba44592d218ae609148e03
$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
mpon/kandan     latest              6cffc5599b7e        15 seconds ago      225.7 MB
centos              latest              0c752394b855        2 days ago          124.1 MB
ubuntu              latest              ad892dd21d60        7 days ago          275.4 MB
  • commitしたimeageでコンテナ起動。環境変数はクリアされるのか。profile.dは読まれないっぽい
$ sudo docker run -t -i mpon/kandan /bin/bash
bash-4.1# echo $http_proxy

bash-4.1# cat /etc/profile.d/proxy.sh
export http_proxy="http://example.com/"
bash-4.1# exit