Dockerの公式チュートリアルをやる
これ
0. バージョンの確認
$ docker version Docker Emulator version 0.1.3 Emulating: Client version: 0.5.3 Server version: 0.5.3 Go version: go1.1
1. オンラインのDockerHubでtutorialのimageを見つける
$ docker search tutorial Found 1 results matching your query ("tutorial") NAME DESCRIPTION learn/tutorial An image for the interactive tutorial
2. コンテナimageをダウンロード
$ docker pull tutorial Pulling repository tutorial 2013/06/19 19:27:03 HTTP code: 404 $ docker images ubuntu latest 8dbd9e392a96 4 months ago 131.5 MB (virtual 131.5 MB) learn/tutorial latest 8dbd9e392a96 2 months ago 131.5 MB (virtual 131.5 MB) learn/ping latest effb66b31edb 10 minutes ago 11.57 MB (virtual 143.1 MB) $ docker pull learn/tutorial Pulling repository learn/tutorial from https://index.docker.io/v1 Pulling image 8dbd9e392a964056420e5d58ca5cc376ef18e2de93b5cc90e868a1bbc8318c1c (precise) from ubuntu Pulling image b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc (12.10) from ubuntu Pulling image 27cf784147099545 () from tutorial
3. コンテナを起動してHello worldを実行
$ docker run learn/tutorial echo 'hello world' 'hello world'
4. imageにpingをインストール
$ docker run learn/tutorial apt-get install -y ping debconf: delaying package configuration, since apt-utils is not installed Fetched 56.1 kB in 1s (50.3 kB/s) Selecting previously unselected package iputils-ping. (Reading database ... 7545 files and directories currently installed.) Unpacking iputils-ping (from .../iputils-ping_3%3a20101006-1ubuntu1_amd64.deb) ... Setting up iputils-ping (3:20101006-1ubuntu1) ...
5. 変更を保存
$ docker ps -l ID IMAGE COMMAND CREATED STATUS PORTS 6982a9948422 ubuntu:12.04 apt-get install ping 1 minute ago Exit 0 you@tutorial:~$ docker commit Usage: Docker commit [OPTIONS] CONTAINER [REPOSITORY [TAG]] Create a new image from a container's changes -author="": Author (eg. "John Hannibal Smith <hannibal@a-team.com>" -m="": Commit message -run="": Config automatically applied when the image is run. (ex: {"Cmd": ["cat", "/world"], "PortSpecs": ["22"]}') $ docker commit 6982a9948422 learn/ping effb66b31edb
6. 新しいimageでpingを実行
$ docker run learn/ping ping www.google.com PING www.google.com (74.125.239.129) 56(84) bytes of data. 64 bytes from nuq05s02-in-f20.1e100.net (74.125.239.148): icmp_req=1 ttl=55 time=2.23 ms 64 bytes from nuq05s02-in-f20.1e100.net (74.125.239.148): icmp_req=2 ttl=55 time=2.30 ms 64 bytes from nuq05s02-in-f20.1e100.net (74.125.239.148): icmp_req=3 ttl=55 time=2.27 ms 64 bytes from nuq05s02-in-f20.1e100.net (74.125.239.148): icmp_req=4 ttl=55 time=2.30 ms 64 bytes from nuq05s02-in-f20.1e100.net (74.125.239.148): icmp_req=5 ttl=55 time=2.25 ms 64 bytes from nuq05s02-in-f20.1e100.net (74.125.239.148): icmp_req=6 ttl=55 time=2.29 ms 64 bytes from nuq05s02-in-f20.1e100.net (74.125.239.148): icmp_req=7 ttl=55 time=2.23 ms 64 bytes from nuq05s02-in-f20.1e100.net (74.125.239.148): icmp_req=8 ttl=55 time=2.30 ms 64 bytes from nuq05s02-in-f20.1e100.net (74.125.239.148): icmp_req=9 ttl=55 time=2.35 ms -> This would normally just keep going. However, this emulator does not support Ctrl-C, so we quit here.
7. コンテナをチェック
$ docker ps ID IMAGE COMMAND CREATED STATUS PORTS efefdc74a1d5 learn/ping:latest ping www.google.com 37 seconds ago Up 36 seconds you@tutorial:~$ docker inspect Usage: Docker inspect CONTAINER|IMAGE [CONTAINER|IMAGE...] Return low-level information on a container/image $ docker inspect efefdc74a1d5 [2013/07/30 01:52:26 GET /v1.3/containers/efef/json { "ID": "efefdc74a1d5900d7d7a74740e5261c09f5f42b6dae58ded6a1fde1cde7f4ac5", "Created": "2013-07-30T00:54:12.417119736Z", "Path": "ping", "Args": [ "www.google.com" ], "Config": { "Hostname": "efefdc74a1d5", "User": "", "Memory": 0, "MemorySwap": 0, "CpuShares": 0, "AttachStdin": false, "AttachStdout": true, "AttachStderr": true, "PortSpecs": null, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": null, "Cmd": [ "ping", "www.google.com" ], "Dns": null, "Image": "learn/ping", "Volumes": null, "VolumesFrom": "", "Entrypoint": null }, "State": { "Running": true, "Pid": 22249, "ExitCode": 0, "StartedAt": "2013-07-30T00:54:12.424817715Z", "Ghost": false }, "Image": "a1dbb48ce764c6651f5af98b46ed052a5f751233d731b645a6c57f91a4cb7158", "NetworkSettings": { "IPAddress": "172.16.42.6", "IPPrefixLen": 24, "Gateway": "172.16.42.1", "Bridge": "docker0", "PortMapping": { "Tcp": {}, "Udp": {} } }, "SysInitPath": "/usr/bin/docker", "ResolvConfPath": "/etc/resolv.conf", "Volumes": {}, "VolumesRW": {}
8. ImageをDocker Hub Registryへpush
$ docker push learn/ping The push refers to a repository [learn/ping] (len: 1) Processing checksums Sending image list Pushing repository learn/ping (1 tags) Pushing 8dbd9e392a964056420e5d58ca5cc376ef18e2de93b5cc90e868a1bbc8318c1c Image 8dbd9e392a964056420e5d58ca5cc376ef18e2de93b5cc90e868a1bbc8318c1c already pushed, skipping Pushing tags for rev [8dbd9e392a964056420e5d58ca5cc376ef18e2de93b5cc90e868a1bbc8318c1c] on {https://registry-1.docker.io/v1/repositories/learn/ping/tags/latest} Pushing a1dbb48ce764c6651f5af98b46ed052a5f751233d731b645a6c57f91a4cb7158 Pushing 11.5 MB/11.5 MB (100%) Pushing tags for rev [a1dbb48ce764c6651f5af98b46ed052a5f751233d731b645a6c57f91a4cb7158] on {https://registry-1.docker.io/v1/repositories/learn/ping/tags/latest}
おしまい
_ _ _ _ __ _____| | | __| | ___ _ __ ___ | | \ \ /\ / / _ \ | | / _` |/ _ \| '_ \ / _ \ | | \ V V / __/ | | | (_| | (_) | | | | __/ |_| \_/\_/ \___|_|_| \__,_|\___/|_| |_|\___| (_) ## . ## ## ## == ## ## ## ## === /""""""""""""""""\___/ === ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~ \______ o __/ \ \ __/ \____\______/ | | __ | __ __ | _ __ _ / \| / \ / |/ / _\ | \__/| \__/ \__ |\_ \__ |