Docker で用いるサブコマンドまとめ
images
$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker/sshd latest f97b8db88f79 29 minutes ago 594 MB
ubuntu 16.04-ssh 79bdfa4d5921 36 minutes ago 594 MB
centos centos7-emacs-installed fb048d27b696 27 hours ago 557 MB
httpd 2.4.29 a8bdc7fdaa4f 8 days ago 177 MB
ubuntu 16.04 747cb2d60bbe 3 weeks ago 122 MB
centos centos7 196e0ce0c9fb 6 weeks ago 197 MB
inspect
$ sudo docker inspect docker/sshd
[
{
"Id": "sha256:f97b8db88f79d396a2556a07dc93bea663a0e6032e937d18f1fbf58d65c4d096",
"RepoTags": [
"docker/sshd:latest"
],
"RepoDigests": [],
"Parent": "sha256:79bdfa4d5921063b215d9e61a97725c9ffb18f77f496509af8a14044bc254976",
"Comment": "",
"Created": "2017-11-01T17:17:23.216191941Z",
"Container": "081308af8af2837550232c320ecea372239b7f2d00159f1412153dc2fbc3663b",
"ContainerConfig": {
"Hostname": "081308af8af2",
"Domainname": "",
"User": "",
"AttachStdin": true,
"AttachStdout": true,
"AttachStderr": true,
"Tty": true,
"OpenStdin": true,
"StdinOnce": true,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/bash"
],
"Image": "ubuntu:16.04-ssh",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {}
},
"DockerVersion": "17.03.2-ce",
"Author": "",
"Config": {
"Hostname": "",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"22/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/sh",
"-c",
"/usr/sbin/sshd -D"
],
"ArgsEscaped": true,
"Image": "",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {}
},
"Architecture": "amd64",
"Os": "linux",
"Size": 593905890,
"VirtualSize": 593905890,
"GraphDriver": {
"Name": "overlay2",
"Data": {
"LowerDir": "/var/lib/docker/overlay2/665de06caef35f377241a483892f628fb287aeffaaf2a82c671a926405b53e36/diff:/var/lib/docker/overlay2/223f1c5e092d3dfcc9d5b42fbff7bc1de846c8850c1432320fc56d73c0575d33/diff:/var/lib/docker/overlay2/d6b52caa1c21f00f692fde709d38b09288b80a3b285faa2655b222f4ab9e7541/diff:/var/lib/docker/overlay2/ca915124fb1ca471362c1131d7b53f6e13a39a8b536018580b30d81ea33d162d/diff:/var/lib/docker/overlay2/f91159d82b6e62634acff77cbfcdaf6066a95de6517e5745ea0de334649d21d1/diff:/var/lib/docker/overlay2/3932a124fc07113be4f4dc71da0a08f00b853af6c4951b7a13270c99778899b0/diff",
"MergedDir": "/var/lib/docker/overlay2/dc2ffb8d6b927365f9782b507eefe6ca7f3fd886437636adb200661191162507/merged",
"UpperDir": "/var/lib/docker/overlay2/dc2ffb8d6b927365f9782b507eefe6ca7f3fd886437636adb200661191162507/diff",
"WorkDir": "/var/lib/docker/overlay2/dc2ffb8d6b927365f9782b507eefe6ca7f3fd886437636adb200661191162507/work"
}
},
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:0f5ff0cf6a1c53f94b15f03536c490040f233bc455f1232f54cc8eb344a3a368",
"sha256:cd181336f1422e8169eaa7be4abe0d06c71340e515e7e44baba2f842b54f67e2",
"sha256:b97229212d30d1b0bbb04aaeac57646791f2073be372474c9fe02cd7dfe65c98",
"sha256:4589f96366e69fc4ed9c118f43bd7ccd033d710eba8c1ba3b6d758b2cba668a7",
"sha256:49907af65b0a659b157be1dc099c3f71c42dfe2e599998e3157ebcf1b12a5652",
"sha256:943356d10977eb1f4dc9b758c21f52e01e05f77297ae6b222738acffb6e514d6",
"sha256:cbe9de0af3df8805c477251309832f7ead2200d1baa94a66a9f6c106ad4e8f54"
]
}
}
]
$ sudo docker inspect -f '{{.Config.Cmd}}' docker/sshd
[/bin/sh -c /usr/sbin/sshd -D]
history
sudo docker history docker/sshd
IMAGE CREATED CREATED BY SIZE COMMENT
f97b8db88f79 37 minutes ago /bin/bash 340 kB
79bdfa4d5921 44 minutes ago /bin/bash 472 MB
747cb2d60bbe 3 weeks ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0 B
<missing> 3 weeks ago /bin/sh -c mkdir -p /run/systemd && echo '... 7 B
<missing> 3 weeks ago /bin/sh -c sed -i 's/^#\s*\(deb.*universe\... 2.76 kB
<missing> 3 weeks ago /bin/sh -c rm -rf /var/lib/apt/lists/* 0 B
<missing> 3 weeks ago /bin/sh -c set -xe && echo '#!/bin/sh' >... 745 B
<missing> 3 weeks ago /bin/sh -c #(nop) ADD file:5b334adf9d9a225... 122 MB
commit
$ sudo docker commit bb3ba7b6a5a7 myimage:v1.0
sha256:86b78befb41e7b67dce010d4454ca0600daf10d5fc81c797909be2a7ecfeadcf
$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
myimage v1.0 86b78befb41e 6 seconds ago 594 MB
docker/sshd latest f97b8db88f79 40 minutes ago 594 MB
ubuntu 16.04-ssh 79bdfa4d5921 46 minutes ago 594 MB
centos centos7-emacs-installed fb048d27b696 27 hours ago 557 MB
httpd 2.4.29 a8bdc7fdaa4f 8 days ago 177 MB
ubuntu 16.04 747cb2d60bbe 3 weeks ago 122 MB
centos centos7 196e0ce0c9fb 6 weeks ago 197 MB
save
$ sudo docker save myimage:v1.0 > myimage-v.1.0.tar
load
$ cat myimage-v.1.0.tar | sudo docker load
Loaded image: myimage:v1.0
stats
$ sudo docker stats
ONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
bb3ba7b6a5a7 0.00% 3.23 MiB / 15.67 GiB 0.02% 5.29 kB / 5.46 kB 0 B / 504 kB 0
9ae657fb11fd 0.00% 6.629 MiB / 15.67 GiB 0.04% 28.6 kB / 20 kB 0 B / 0 B 0
exec
$ sudo docker exec -t bb3ba7b6a5a7 ls
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr
cp
$ sudo docker cp bb3ba7b6a5a7:/etc /tmp
$ sudo ls /tmp/etc/
ImageMagick-6 bindresvport.blacklist debian_version environment gshadow hosts.deny issue.net libpaper.d magic.mime networks passwd- rc1.d rmt shadow subuid ucf.conf
X11 binfmt.d default fonts gshadow- init kernel localtime mailcap nsswitch.conf polkit-1 rc2.d sane.d shadow- subuid- udev
adduser.conf ca-certificates deluser.conf fstab gss init.d ld.so.cache logcheck mailcap.order opt profile rc3.d securetty shells sysctl.conf ufw
alternatives ca-certificates.conf dhcp gai.conf gtk-3.0 inputrc ld.so.conf login.defs mime.types os-release profile.d rc4.d security skel sysctl.d update-motd.d
apt cron.daily dpkg gconf host.conf insserv ld.so.conf.d logrotate.d mke2fs.conf pam.conf python3 rc5.d selinux ssh systemd wgetrc
at-spi2 cron.weekly drirc ghostscript hostname insserv.conf ldap lsb-release modules-load.d pam.d python3.5 rc6.d sensors.d ssl terminfo xdg
bash.bashrc dbus-1 emacs group hosts insserv.conf.d legal machine-id mtab papersize rc.local rcS.d sensors3.conf subgid timezone xml
bash_completion.d debconf.conf emacs24 group- hosts.allow issue libaudit.conf magic network passwd rc0.d resolv.conf sgml subgid- tmpfiles.d
diff
$ sudo docker diff bb3ba7b6a5a7
C /run
C /run/motd.dynamic
C /run/sshd.pid
C /run/utmp
C /var/log/lastlog
C /var/log/wtmp