version

core@localhost ~ $ docker version
Client version: 1.1.2
Client API version: 1.13
Go version (client): go1.2
Git commit (client): d84a070
Server version: 1.1.2
Server API version: 1.13
Go version (server): go1.2
Git commit (server): d84a070

info

core@localhost ~ $ docker info
Containers: 5
Images: 7
Storage Driver: btrfs
Execution Driver: native-0.2
Kernel Version: 3.15.8+

pull (公開されているイメージの取得)

イメージのレポジトリ https://registry.hub.docker.com/

core@localhost ~ $ sudo docker pull centos:centos6
Pulling repository centos
b1bd49907d55: Download complete
511136ea3c5a: Download complete
34e94e67e63a: Download complete

push (イメージの公開)

Docker Hub

commit (現在の状態をイメージとして保存する)

core@localhost ~ $ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                          PORTS               NAMES
abb0ba529ee9        centos:centos6      /bin/bash           5 minutes ago       Exited (0) About a minute ago                       high_pare

core@localhost ~ $ docker commit abb0ba529ee9 cent6_apache
633e8b36e0837adccc606fda644f9067e7cd1dbd66ee24d14eb491d8738ad1cd

images (ローカルに保存されているイメージの一覧)

core@localhost ~ $ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
cent6_monit         latest              42c1c6908ea4        12 days ago         324.2 MB
cent6_apache        latest              633e8b36e083        13 days ago         300.6 MB
centos              centos6             b1bd49907d55        3 weeks ago         212.5 MB
centos              latest              b157b77b1a65        3 weeks ago         243.7 MB

run (インタラクティブ実行)

core@localhost ~ $ docker run -i -t -h centos centos:centos6 /bin/bash
bash-4.1# cat /etc/redhat-release
CentOS release 6.5 (Final)
bash-4.1# exit
exit

attach (コンテナに再接続)

[Ctrl+P]⇒[Ctrl+Q] でコンテナから抜けたあと、再接続したいとき

core@localhost ~ $ docker run -i -t centos /bin/bash

bash-4.2# 

core@localhost ~ $ docker ps
CONTAINER ID        IMAGE                COMMAND             CREATED             STATUS              PORTS                                            NAMES
3b5328ae594f        centos:latest        /bin/bash           21 seconds ago      Up 20 seconds                                                        agitated_kirch
core@localhost ~ $ docker attach 3b5328ae594f

bash-4.2#

run (デーモン実行、ポート転送)

core@localhost ~ $ docker run -p 8080:80 -d cent6_apache /usr/sbin/apachectl -DFOREGROUND
47b822b0fe8a81810f7cd977ca79bab7f8ffeaff9bd8aac632e06b181d98388b
core@localhost ~ $ docker ps
CONTAINER ID        IMAGE                 COMMAND                CREATED             STATUS              PORTS                  NAMES
47b822b0fe8a        cent6_apache:latest   /usr/sbin/apachectl    6 seconds ago       Up 5 seconds        0.0.0.0:8080->80/tcp   insane_lovelace

create (Volume コンテナを作る 1.3〜)

$ sudo docker create --name test1 atsushi/volume
80809efcb52add143e1080b138aeef91a517d34c869d8170ee211013c4916697
$ sudo docker ps -a
CONTAINER ID        IMAGE                           COMMAND                CREATED             STATUS                   PORTS               NAMES
80809efcb52a        atsushi/volume:latest           "/bin/sh -c /bin/sh"   7 seconds ago                                                    test1

Docker Volume


$ sudo docker run -i -t --name test1 atsushi/volume /bin/ash
# / exit

のように、コンテナを run で作って直ぐに終了し、その残骸を Volume コンテナにするのと同じ。
ちょっと見た目スマートなコマンドを追加しただけ

run (ホストのファイルシステムをマウント)

Docker Volume

ps

logs (デーモンのstdout)

core@localhost ~ $ docker logs a71eb9999916
monit: generated unique Monit id debeff217c0adbe6fd09542bc291d04f and stored to '/var/monit/id'
Starting monit daemon with http interface at [0.0.0.0:2812]
Starting monit daemon with http interface at [0.0.0.0:2812]

常時監視 (tail -f みたいに)

core@localhost ~ $ docker logs -f a71eb9999916
monit: generated unique Monit id debeff217c0adbe6fd09542bc291d04f and stored to '/var/monit/id'
Starting monit daemon with http interface at [0.0.0.0:2812]
Starting monit daemon with http interface at [0.0.0.0:2812]

stop

core@localhost ~ $ docker ps
CONTAINER ID        IMAGE                 COMMAND                CREATED             STATUS              PORTS                  NAMES
e053d621946c        cent6_apache:latest   /usr/sbin/apachectl    8 seconds ago       Up 8 seconds        0.0.0.0:8080->80/tcp   naughty_curie

core@localhost ~ $ docker stop e053 -t 10
e053

core@localhost ~ $ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

コンテナ内のすべてのプロセスに SIGKILL が発行される。プロセス終了を -t 秒待つ (未指定時10秒)

kill

core@localhost ~ $ docker ps
CONTAINER ID        IMAGE                 COMMAND                CREATED             STATUS              PORTS                  NAMES
e053d621946c        cent6_apache:latest   /usr/sbin/apachectl    8 seconds ago       Up 8 seconds        0.0.0.0:8080->80/tcp   naughty_curie

core@localhost ~ $ docker kill e053
e053

core@localhost ~ $ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

コンテナを強制終了する。動いているプロセスの終了を待たない

start, restart

core@localhost ~ $ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

core@localhost ~ $ docker start e053
e053

core@localhost ~ $ docker ps
CONTAINER ID        IMAGE                 COMMAND                CREATED             STATUS              PORTS                  NAMES
e053d621946c        cent6_apache:latest   /usr/sbin/apachectl    23 minutes ago      Up 2 seconds        0.0.0.0:8080->80/tcp   naughty_curie

コンテナを再起動する

top

core@localhost ~ $ docker top e053
UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
root                827                 681                 0                   12:33               ?                   00:00:00            /bin/sh /usr/sbin/apachectl -DFOREGROUND
root                846                 827                 0                   12:33               ?                   00:00:00            /usr/sbin/httpd -DFOREGROUND
48                  847                 846                 0                   12:33               ?                   00:00:00            /usr/sbin/httpd -DFOREGROUND
48                  848                 846                 0                   12:33               ?                   00:00:00            /usr/sbin/httpd -DFOREGROUND
48                  849                 846                 0                   12:33               ?                   00:00:00            /usr/sbin/httpd -DFOREGROUND
48                  850                 846                 0                   12:33               ?                   00:00:00            /usr/sbin/httpd -DFOREGROUND
48                  851                 846                 0                   12:33               ?                   00:00:00            /usr/sbin/httpd -DFOREGROUND
48                  852                 846                 0                   12:33               ?                   00:00:00            /usr/sbin/httpd -DFOREGROUND
48                  853                 846                 0                   12:33               ?                   00:00:00            /usr/sbin/httpd -DFOREGROUND
48                  854                 846                 0                   12:33               ?                   00:00:00            /usr/sbin/httpd -DFOREGROUND

コンテナ内のプロセス一覧

inspect (コンテナの設定情報を取得)

core@localhost ~ $ docker inspect e053
[{
    "Args": [
        "-DFOREGROUND"
    ],
    "Config": {
        "AttachStderr": false,
        "AttachStdin": false,
        "AttachStdout": false,
        "Cmd": [
            "/usr/sbin/apachectl",
            "-DFOREGROUND"
        ],
        "CpuShares": 0,
        "Cpuset": "",
...

rm (コンテナ削除)

core@localhost ~ $ docker ps -a
CONTAINER ID        IMAGE                 COMMAND                CREATED             STATUS                     PORTS                                            NAMES
e053d621946c        cent6_apache:latest   /usr/sbin/apachectl    45 hours ago        Up 45 hours                0.0.0.0:8080->80/tcp                             naughty_curie
3b5328ae594f        centos:latest         /bin/bash              10 days ago         Exited (0) 8 days ago                                                       agitated_kirch
01bf1f0ca471        centos:latest         /bin/bash              10 days ago         Exited (0) 10 days ago                                                      angry_poincare
a98f6842e4b9        centos:latest         /bin/bash              10 days ago         Exited (0) 10 days ago                                                      lonely_blackwell7
a71eb9999916        cent6_monit:latest    /usr/bin/monit -I      12 days ago         Exited (0) 46 hours ago    0.0.0.0:10022->22/tcp, 0.0.0.0:12812->2812/tcp   angry_archimedes
7d6431c9008d        d34528b704d1          /bin/bash              12 days ago         Exited (0) 12 days ago                                                      elegant_fermi
0197352d1247        d34528b704d1          /usr/bin/monit -I      12 days ago         Exited (0) 12 days ago                                                      cranky_davinci
6b7ac43f26cb        d34528b704d1          /usr/bin/monit -I      12 days ago         Exited (0) 12 days ago                                                      insane_einstein
a62db2affdf6        centos:centos6        /bin/bash              13 days ago         Exited (130) 12 days ago                                                    compassionate_archimedes

core@localhost ~ $ docker rm a62
a62

core@localhost ~ $ docker ps -a
CONTAINER ID        IMAGE                 COMMAND                CREATED             STATUS                    PORTS                                            NAMES
e053d621946c        cent6_apache:latest   /usr/sbin/apachectl    45 hours ago        Up 45 hours               0.0.0.0:8080->80/tcp                             naughty_curie
3b5328ae594f        centos:latest         /bin/bash              10 days ago         Exited (0) 8 days ago                                                      agitated_kirch
01bf1f0ca471        centos:latest         /bin/bash              10 days ago         Exited (0) 10 days ago                                                     angry_poincare
a98f6842e4b9        centos:latest         /bin/bash              10 days ago         Exited (0) 10 days ago                                                     lonely_blackwell7
a71eb9999916        cent6_monit:latest    /usr/bin/monit -I      12 days ago         Exited (0) 46 hours ago   0.0.0.0:10022->22/tcp, 0.0.0.0:12812->2812/tcp   angry_archimedes
7d6431c9008d        d34528b704d1          /bin/bash              12 days ago         Exited (0) 12 days ago                                                     elegant_fermi
0197352d1247        d34528b704d1          /usr/bin/monit -I      12 days ago         Exited (0) 12 days ago                                                     cranky_davinci
6b7ac43f26cb        d34528b704d1          /usr/bin/monit -I      12 days ago         Exited (0) 12 days ago                                                     insane_einstein

rm で、停止中のイメージを一括削除

core@localhost ~ $ docker rm `docker ps -a -q`
Error response from daemon: Impossible to remove a running container, please stop it first or use -f
3b5328ae594f
01bf1f0ca471
a98f6842e4b9
a71eb9999916
7d6431c9008d
0197352d1247
6b7ac43f26cb
2014/08/24 13:00:43 Error: failed to remove one or more containers
core@localhost ~ $ docker ps -a
CONTAINER ID        IMAGE                 COMMAND                CREATED             STATUS              PORTS                  NAMES
e053d621946c        cent6_apache:latest   /usr/sbin/apachectl    45 hours ago        Up 45 hours         0.0.0.0:8080->80/tcp   naughty_curie
core@localhost ~ $

動作中のコンテナは消せない

rmi (イメージ削除)

core@localhost ~/git/DockerExam/cent6_ssh $ docker images
REPOSITORY                 TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
atsushi/volume             latest              aaf0c39f6953        22 hours ago        226.4 MB
<none>                     <none>              29abb8104dbc        22 hours ago        226.4 MB
<none>                     <none>              d0d5c142dd55        23 hours ago        226.4 MB
atsushi/cent6_monit_ssh    latest              43db0564a524        23 hours ago        452.9 MB
atsushi/ubuntu_monit_ssh   latest              c53db8fef482        23 hours ago        409.9 MB
ubuntu                     14.10               75204fdb260b        3 weeks ago         226.4 MB
cent6_monit                latest              42c1c6908ea4        3 weeks ago         324.2 MB
cent6_apache               latest              633e8b36e083        3 weeks ago         300.6 MB
centos                     centos6             b1bd49907d55        5 weeks ago         212.5 MB
centos                     latest              b157b77b1a65        5 weeks ago         243.7 MB
 
core@localhost ~/git/DockerExam/cent6_ssh $ docker rmi 29a
29a

rmiで名無しのイメージを一括削除

core@localhost ~/git/DockerExam/cent6_ssh $ docker images
REPOSITORY                 TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
atsushi/volume             latest              aaf0c39f6953        22 hours ago        226.4 MB
<none>                     <none>              29abb8104dbc        22 hours ago        226.4 MB
<none>                     <none>              d0d5c142dd55        23 hours ago        226.4 MB
atsushi/cent6_monit_ssh    latest              43db0564a524        23 hours ago        452.9 MB
atsushi/ubuntu_monit_ssh   latest              c53db8fef482        23 hours ago        409.9 MB
ubuntu                     14.10               75204fdb260b        3 weeks ago         226.4 MB
cent6_monit                latest              42c1c6908ea4        3 weeks ago         324.2 MB
cent6_apache               latest              633e8b36e083        3 weeks ago         300.6 MB
centos                     centos6             b1bd49907d55        5 weeks ago         212.5 MB
centos                     latest              b157b77b1a65        5 weeks ago         243.7 MB

core@localhost ~/git/DockerExam/cent6_ssh $ docker rmi `docker images | grep none | awk '{print $3}'`
Deleted: 29abb8104dbc29809b054248b23735e9b9fce63fb78869f6ff56875ff1ccf5c0
Deleted: c04dbdacd0abc24d7d07fe90082ec6f61397a33b9649dbe93b653620ff8eb1b1
Deleted: 86f962d871d68fbc4ab3b2c54ac5e2e4c0785a153265a4c4bdbbd848a163558b
Deleted: 5b8d6571f75dc239da07858aeca92497166cf2a70e61624a2bbccbfe9a7954d9

core@localhost ~/git/DockerExam/cent6_ssh $ docker images
REPOSITORY                 TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
atsushi/volume             latest              aaf0c39f6953        22 hours ago        226.4 MB
atsushi/cent6_monit_ssh    latest              43db0564a524        23 hours ago        452.9 MB
atsushi/ubuntu_monit_ssh   latest              c53db8fef482        24 hours ago        409.9 MB
ubuntu                     14.10               75204fdb260b        3 weeks ago         226.4 MB
cent6_monit                latest              42c1c6908ea4        3 weeks ago         324.2 MB
cent6_apache               latest              633e8b36e083        3 weeks ago         300.6 MB
centos                     centos6             b1bd49907d55        5 weeks ago         212.5 MB
centos                     latest              b157b77b1a65        5 weeks ago         243.7 MB

export, import

load, save

cp (コンテナ内のファイルをホストにコピー)

$ docker cp CONTAINER:filename ./

Docker


添付ファイル: fileforward.png 2052件 [詳細]

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS   sitemap
Last-modified: 2015-02-26 (木) 01:37:48 (3570d)
Short-URL: http://at-sushi.com/pukiwiki/index.php?cmd=s&k=cfcbe1a48c
ISBN10
ISBN13
9784061426061