Dockerã§Immutable Infrastractureã«è§¦ãã
Dockerã¨ã¯
Dockerã¯ã¯ã©ã¦ããã³ãã§ããdotCloudããªã¼ãã³ã½ã¼ã¹ã§å ¬éãã¦ããOSã¬ãã«ä»®æ³åãæä¾ããã½ããã¦ã§ã¢ã§ãããLXCã¨AUFSããã¼ã¹ã«ä½ããã¦ãã¾ãã
LXC (LinuX Containers)
LXCã¯ãLinuxä¸ã§OSã¬ãã«ä»®æ³åãæä¾ããä»çµã¿ã§ãã
LXCãç¨ãããã¨ã§ä¸ã¤ã®ã³ã³ããã¼ã«ãã¹ãä¸ã§ãã³ã³ããã¨å¼ã°ããåä½ã§è¤æ°ã®éé¢ãããLinuxã·ã¹ãã ãèµ°ãããäºãå¯è½ã¨ãªãã¾ãã
ä»®æ³åã®åé¡ã¨ãã¦ã¯ãç©çãã·ã³ã«ãã¡ã¼ã ã¦ã§ã¢ã¨ãã¦ãã¤ãã¼ãã¤ã¶ãå
èµãããã¼ãã¦ã§ã¢ã«ããä»®æ³åãè¡ãIBM PowerVM, æ¥ç« Virtageã
ç©çãã·ã³ä¸ã«ã½ããã¦ã§ã¢ã¨ãã¦ãã¤ãã¼ãã¤ã¶ãå°å
¥ããã½ããã¦ã§ã¢ã«ããä»®æ³åãè¡ãVMWare vSphere, Xenã
ãã¹ãOSã«ã«ã¼ãã«ã¢ã¸ã¥ã¼ã«ã¨ãã¦ãã¤ãã¼ãã¤ã¶æ©è½ã追å ããã½ããã¦ã§ã¢ã«ããä»®æ³åãè¡ãKVMãªã©ãããã¾ãã
対ãã¦LXCã®OSã¬ãã«ä»®æ³åã¯OSã¸ã®ã¢ã¯ã»ã¹ã®ä»®æ³åãè¡ãããã¹ãå
ã®éé¢ãããç°å¢ã§ä»®æ³ãã·ã³ãåããæè¡ã§ãã
ã¤ã¾ããåå¥ã®ããã»ã¹ã¨ãããã¯ã¼ã¯ã¹ãã¼ã¹ãä½ãåºãä»®æ³ç°å¢ã§ããã¨è¨ããã¨ãã§ãã¾ãã
OSå é¨ã¯ç©çãªã½ã¼ã¹ã管çããã«ã¼ãã«ç©ºéã¨ã¦ã¼ã¶ã¼ããã»ã¹ãå®è¡ããã¦ã¼ã¶ã¼ç©ºéã«åãããã³ã³ããåã®ä»®æ³åã§ã¯ã«ã¼ãã«ã®æ©è½ã«ããè¤æ°ã®ã¦ã¼ã¶ã¼ç©ºéãä½ãåºããã¨ã§ãã¦ã¼ã¶ã¼ããã»ã¹ããè¦ãããªã½ã¼ã¹ãåå²ãã¾ãã
LXCã¯ããã¹ãããã³ã²ã¹ãOSãLinuxã«éå®ãããã¨ããç¹ã¯ããã¾ãããç©çãã·ã³ã®ã·ãã¥ã¬ã¼ã·ã§ã³ãè¡ã£ã¦ããªãã®ã§ãVPSãEC2ãªã©ã®ä»®æ³ãã·ã³ä¸ã§ãåé¡ãªãåä½ãããã¤ãã·ã³ãèµ·åããããã»ã¹ãä¸è¦ã¨ãªãã®ã§ããã¤ããã©ã¼ãã³ã¹ãã¤çãªã½ã¼ã¹ãªä»®æ³åãã¼ã«ã¨ãã¦æå¹ã§ãã
AUFS (Advanced multi layered Unification FileSystem)
AUFSã¯UnionFSã¨å¼ã°ããç°ãªããã¡ã¤ã«ã·ã¹ãã ã®ãã¡ã¤ã«ããã£ã¬ã¯ããªãééçã«éãåãããã²ã¨ã¤ã®ãã¡ã¤ã«ããªã¼ãæ§æã§ãããã¡ã¤ã«ã·ã¹ãã ã®å®è£
ã®ä¸ã¤ã§ãã
å
ã®ä»®æ³ãã·ã³ã¤ã¡ã¼ã¸ãæ¸ãæãããã¨ãªããæ´æ°ãçºçããé¨åãå¥ã®å ´æã«æ¸ãè¾¼ããããä»®æ³ãã·ã³ã®ç«ã¡ä¸ãæã«ã¤ã¡ã¼ã¸ã®ã³ãã¼çºçãããããã«ä½¿ãå§ãããã¨ãã§ãã¾ãã
ãªãDockerã
Dockerã使ã£ã¦ã¿ããã¨æã£ãã¯ãImmutable Infrastructure ã¨ããèãæ¹ãç¥ã£ãããã§ãã
Immutable Infrastructureã¯ã6wunderlist.comã®CTOã§ããããæ
ç±ããã°ã©ãã¼ãã®èè
ã§ããChad Fowleræ°ã®ããã°ã§Trash Your Servers and Burn Your Code: Immutable Infrastructure and Disposable Componentsã¨ããè¨äºã§ç¶´ããã¦ãã¾ãã
Immutable Infrastracture ã¨ã¯
Immutableã¨ã¯ãç¶æ
ãå¤æ´åºæ¥ãªããã¨ãæãã¦ãã¾ãã
ã¤ã¾ããImmutable Infrastractureã¨ã¯ãéç¨ä¸ã®ãµã¼ãã¼ã«å¤æ´ãå ããªããã¨ããã¢ããã¼ãã§ãµã¼ãã¼ã管çãããã¨ãæå³ãã¦ãã¾ãã
Immutable Infrastractureã®èãã§ã¯ããµã¼ãã¼ã®è¨å®ãå¤æ´ããå ´åããã®å¤æ´ãå ããæ°ãããµã¼ãã¼ãç¨æããã¢ããªã±ã¼ã·ã§ã³ã®ãããã¤ãæ°ãããµã¼ãã¼ãç«ã¡ä¸ãã¦ãã¡ãã«ãããã¤ãè¡ãã¾ãã
稼åä¸ã®ãµã¼ãã¼ã«SSHã§ãã°ã¤ã³ãã¦è¨å®ãå¤æ´ãããããªãã¨ã¯ããã常ã«ãµã¼ãã¼ã追å ãã¦ãããDNSãå¼µãæ¿ããå¾ãåç
§ãããªããªã£ããµã¼ãã¼ãç ´æ£ãã¾ãã
Immutable Infrastractureã®å®ç¾ã«ã¯ãBlue-Green Deploymentã¨å¼ã°ããææ³ãã¨ãã¾ãã
ThoughtWorksã®ã½ããã¦ã§ã¢ããªããªã¼ã³ã³ãµã«ã¿ã³ãã§ããKief Morisæ°ã¯ãããã°ã§Immutable Serverã«ã¤ãã¦èª¬æãã¦ãã¾ãã
èªåæ§æãã¼ã«(CFEngineãPuppetãChef)ã¯ãµã¼ããã©ã®ããã«æ§æããããå®ç¾©ããæ°ãããã·ã³ãæ¢åã®ãã·ã³ãè¦ç´ã«å¾ã£ãæ§æã«ã§ãã¾ãããã®ãããªãã¼ã«ã¯èå¼±ãªSnowflakeServersã®åé¡ãé¿ãã解ä½ã¨åæ§ç¯ãå¯è½ãªPhoenixServersãå®ç¾ãã¾ããã¤ãã¥ã¼ã¿ãã«ãµã¼ãã¯ãã®ãããªãã¼ã«ã使ã£ãããæ¹ã®è«ççãªå¸°çµã¨è¨ãã¾ãããµã¼ãã1度é ç½®ãããã2度ã¨å¤æ´ããã«ãæ°ããã¤ã³ã¹ã¿ã³ã¹ã«ç½®ãæããã®ã§ãã
ã¤ã¾ããä»®æ³ãã·ã³ãç¶æ ãæã£ã¦ãããããã«ãåªçæ§ãèªå·±ä¿®å¾©æ§ã®ããã«æ¡ä»¶ãä»ãã¦ã»ããã¢ããã®å¦çãæ¸ããªããã°ãªããããããå®æçã«æ§æ管çãã¼ã«ã®ãµã¼ãã¼ã¨éä¿¡ããå¿ è¦ããã£ãããä»®æ³ãã·ã³ãä¸å¤ã ã¨ããåæã«ç«ã¦ã°ããã®é¢åã軽æ¸ãããã¨ãããã¨ã§ãã
ãã¡ããæ§æ管çãã¼ã«ãä¸è¦ã«ãªãããã§ã¯ãªãããã¼ã¹ã¨ãªãä»®æ³ãã·ã³ã®æ§ç¯ããååèµ·åå¾ã®ä»®æ³ãã·ã³ã«å¯¾ãã¦ãã·ã³ãã¨ã®å¤æ´ãè¨å®ããããã«ä½¿ããã¦ããã§ãããã
ãããããã§ã¯ChefãPuppetã®ãããªãµã¼ãã¼/ã¯ã©ã¤ã¢ã³ãã¿ã¤ãã§ã¯ãªããAnsibleã®ãããªãã®ã®æ¹ãåãã¦ããããããã¾ããã
dockerã«è§¦ã£ã¦ã¿ã
ä»åã¯è»½ãdockerã«è§¦ã£ã¦è¦ããã¨ã«ãã¾ãããããã¹ãOSã¯Mac OS X 10.8.5ã§ãVIrtual Boxã¨vagrantã¯ã»ããã¢ããæ¸ã¿ã¨ãã¾ãã
CoreOS
dockerã¯LXCãç¨ãã¦ããã®ã§ãLinuxãã¹ãã§ããå®è¡ã§ãã¾ããã
å¾ã£ã¦ã¾ãã¯OSXä¸ã«Linuxãç«ã¡ä¸ãã¾ãã
CoreOSã¨ã¯ãLinux kernelã¨systemdã ãã§æ§æããã軽éãªãã£ã¹ããªãã¥ã¼ã·ã§ã³ã§ãããdockerãåããããã®æå°æ§æã¨ãã¦ç¨æããã¦ãã¾ãã
git clone https://github.com/coreos/coreos-vagrant/ coreos
cd coreos
vagrant up
vagrant ssh
vagrant sshã§ãã°ã¤ã³ãã¦ã¿ã¾ã
Last login: Thu Oct 10 07:50:15 UTC 2013 from 10.0.2.2 on pts/0
______ ____ _____
/ ____/___ ________ / __ \/ ___/
/ / / __ \/ ___/ _ \/ / / /\__ \
/ /___/ /_/ / / / __/ /_/ /___/ /
\____/\____/_/ \___/\____//____/
core@localhost ~ $ uname -a
Linux localhost 3.10.10+ #1 SMP Fri Oct 4 00:00:19 UTC 2013 x86_64 Intel(R) Core(TM) i5-3230M CPU @ 2.60GHz GenuineIntel GNU/Linux
core@localhost ~ $ cat /etc/gentoo-release
CoreOS release 94.1.0
core@localhost ~ $
dockerãããã©ã«ãã§èµ·åãã¦ãã¾ãã
core@localhost ~ $ ps ax | grep docker
427 ? Ssl 0:00 /usr/bin/docker -d
2195 pts/0 S+ 0:00 grep --colour=auto docker
docker
dockerã§ä½¿ç¨ã§ããã³ãã³ãä¸è¦§ã§ãã
core@localhost ~ $ docker
Usage: docker [OPTIONS] COMMAND [arg...]
-H=[unix:///var/run/docker.sock]: tcp://host:port to bind/connect to or unix://path/to/socket to use
A self-sufficient runtime for linux containers.
Commands:
attach Attach to a running container
build Build a container from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders from the containers filesystem to the host path
diff Inspect changes on a container's filesystem
events Get real time events from the server
export Stream the contents of a container as a tar archive
history Show the history of an image
images List images
import Create a new filesystem image from the contents of a tarball
info Display system-wide information
insert Insert a file in an image
inspect Return low-level information on a container
kill Kill a running container
login Register or Login to the docker registry server
logs Fetch the logs of a container
port Lookup the public-facing port which is NAT-ed to PRIVATE_PORT
top Lookup the running processes of a container
ps List containers
pull Pull an image or a repository from the docker registry server
push Push an image or a repository to the docker registry server
restart Restart a running container
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
search Search for an image in the docker index
start Start a stopped container
stop Stop a running container
tag Tag an image into a repository
version Show the docker version information
wait Block until a container stops, then print its exit code
docker search
ã³ãã³ããããã¯index.docker.ioã§dockerã®imageãæ¤ç´¢ãããã¨ãã§ãã¾ãã
core@localhost ~ $ docker search ubuntu
Found 25 results matching your query ("ubuntu")
NAME DESCRIPTION
shykes/ubuntu
base Another general use Ubuntu base image. Tags available are: latest, quantal (12.10)
ubuntu General use Ubuntu base image. Tags available are: latest, quantal (12.10), precise (12.04).
boxcar/raring Ubuntu Raring 13.04 suitable for testing vagrant-shell
dhrp/ubuntu
creack/ubuntu Tags: 12.04-ssh, 12.10-ssh, 12.10-ssh-lamp. root password: toor
crohr/ubuntu Ubuntu base images. Only lucid (10.04) for now.
pallet/ubuntu2 ubuntu 12.04 with openssh-server. root password `pallet`.
erikh/ubuntu
samalba/wget Test container inherited from ubuntu with wget installed
creack/ubuntu-12-10-ssh
tithonium/rvm-ubuntu The base 'ubuntu' image, with rvm installed, and ruby 1.8.7, 1.9.2, 1.9.3, and 2.0.0 installed. As of this writing: 1.8.7-p371, 1...
dekz/build 13.04 ubuntu with build
ooyala/test-ubuntu
ooyala/test-my-ubuntu
ooyala/test-ubuntu2
ooyala/test-ubuntu3
ooyala/test-ubuntu4
ooyala/test-ubuntu5
surma/go Simple augmentation of the standard Ubuntu image with go1.1.1
nickstenning/python24 Ubuntu with Python 2.4 (in addition to system Python 2.7)
nickstenning/python25 Ubuntu with Python 2.5 (in addition to system Python 2.7)
nickstenning/python26 Ubuntu with Python 2.6 (in addition to system Python 2.7)
nickstenning/python27 Ubuntu with Python 2.7
nickstenning/python32 Ubuntu with Python 3.2 (in addition to system Python 2.7)
docker pull
ã§imageãåå¾ã§ãã¾ãã
baseã¨ååãã¤ããããUbuntu quantal (12.10)ãåå¾ãã¦ã¿ã¾ãã
core@localhost ~ $ docker pull base
Pulling repository base
b750fe79269d: Download complete
27cf78414709: Download complete
docker images
ã§ç¢ºèªãã¦ã¿ã¾ãã
core@localhost ~ $ docker images
REPOSITORY TAG ID CREATED SIZE
base latest b750fe79269d 6 months ago 24.65 kB (virtual 180.1 MB)
base ubuntu-12.10 b750fe79269d 6 months ago 24.65 kB (virtual 180.1 MB)
base ubuntu-quantal b750fe79269d 6 months ago 24.65 kB (virtual 180.1 MB)
base ubuntu-quantl b750fe79269d 6 months ago 24.65 kB (virtual 180.1 MB)
docker run
ã§ä»®æ³ç°å¢ã®ã³ãã³ããå©ããã¨ãã§ãã¾ãã
core@localhost ~ $ docker run base lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 12.10
Release: 12.10
Codename: quantal
docker run
ã®ãªãã·ã§ã³ã§ãã
core@localhost ~ $ docker run
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Run a command in a new container
-a=map[]: Attach to stdin, stdout or stderr.
-c=0: CPU shares (relative weight)
-cidfile="": Write the container ID to the file
-d=false: Detached mode: Run container in the background, print new container id
-dns=[]: Set custom dns servers
-e=[]: Set environment variables
-entrypoint="": Overwrite the default entrypoint of the image
-h="": Container host name
-i=false: Keep stdin open even if not attached
-lxc-conf=[]: Add custom lxc options -lxc-conf="lxc.cgroup.cpuset.cpus = 0,1"
-m=0: Memory limit (in bytes)
-n=true: Enable networking for this container
-p=[]: Expose a container's port to the host (use 'docker port' to see the actual mapping)
-privileged=false: Give extended privileges to this container
-t=false: Allocate a pseudo-tty
-u="": Username or UID
-v=map[]: Bind mount a volume (e.g. from the host: -v /host:/container, from docker: -v /container)
-volumes-from=[]: Mount volumes from the specified container
-w="": Working directory inside the container
-i
,-t
ãªãã·ã§ã³ãã¤ãã¦bashãå©ãã¦ã³ã³ããã«ãã°ã¤ã³ãã¦ã¿ã¾ãã
core@localhost ~ $ docker run -i -t base bash
root@70fb584cf943:/#
hoge.txtãä½æãã¦ãexitãã¾ãã
root@d4c5774e54a0:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin selinux srv sys tmp usr var
root@d4c5774e54a0:/# touch hoge.txt
root@d4c5774e54a0:/# ls
bin boot dev etc hoge.txt home lib lib64 media mnt opt proc root run sbin selinux srv sys tmp usr var
root@d4c5774e54a0:/# exit
exit
å度ãã°ã¤ã³ãã¦ã¿ãã¨
core@localhost ~ $ docker run -i -t base bash
root@8f4a40a0d782:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin selinux srv sys tmp usr var
root@8f4a40a0d782:/#
hoge.txtã¯ããã¾ããã
å®ã¯ãã§ã«ç°ãªãã³ã³ãããä½æããã¦ããããã§ãã
docker ps
ã³ãã³ãã§ã³ã³ããã確èªãããã¨ãã§ãã¾ãã
-a
ãªãã·ã§ã³ã§çµäºããã³ã³ããã確èªã§ãã¾ãã
core@localhost ~ $ docker ps
ID IMAGE COMMAND CREATED STATUS PORTS
core@localhost ~ $ docker ps -a
ID IMAGE COMMAND CREATED STATUS PORTS
8f4a40a0d782 base:latest bash About a minute ago Exit 0
d4c5774e54a0 base:latest bash 2 minutes ago Exit 0
ã³ã³ãããå¿
è¦ãªããªãã°docker rm
ã§åé¤ãã¾ãã
core@localhost ~ $ docker ps -a
ID IMAGE COMMAND CREATED STATUS PORTS
8f4a40a0d782 base:latest bash 4 minutes ago Exit 0
d4c5774e54a0 base:latest bash 5 minutes ago Exit 0
core@localhost ~ $ docker rm 8f4a40a0d782
8f4a40a0d782
core@localhost ~ $ docker ps -a
ID IMAGE COMMAND CREATED STATUS PORTS
d4c5774e54a0 base:latest bash 5 minutes ago Exit 0
-d
ãªãã·ã§ã³ã§ã³ã³ãããããã¯ã°ã©ã¦ã³ãã§èµ·ååºæ¥ã¾ãã
core@localhost ~ $ docker run -i -t -d base bash
82e8a706e7ff
ããã¯ã°ã©ã¦ã³ãã§èµ·åãã¦ããã³ã³ããã«å¯¾ãã¦ã¯ãdocker attach
ã§Attachã§ãã¾ãã
core@localhost ~ $ docker ps
ID IMAGE COMMAND CREATED STATUS PORTS
82e8a706e7ff base:latest bash 4 seconds ago Up 4 seconds
core@localhost ~ $ docker attach 82e8a706e7ff
root@82e8a706e7ff:/#
ã³ã³ããä¸ã§ä½æ¥ãããã®ã³ã³ããã®ç¶æ
ãä¿åãããå ´åã¯ãdocker commit
ã§ã³ã³ããã®ã¤ã¡ã¼ã¸ãä¿åãã¾ãã
index.docker.io ã«ç»é²ããã°ãdocker login
ãã¦docker push
ãããã¨ã§imageã®å
¬éãè¡ããã¨ãå¯è½ã§ãã
docker commit
ã§ã¯ãã³ã³ããIDã®å¾ã«REPOSITORYãæå®ã§ãã¾ãã
å
¬éãããªãã°ãã¦ã¼ã¶ã¼å/ã¤ã¡ã¼ã¸åã®æ¸å¼ã«ããã®ãããã¨æãã¾ãã
core@localhost ~ $ docker ps -a
ID IMAGE COMMAND CREATED STATUS PORTS
12c2c79f0f87 base:latest bash 2 minutes ago Up 2 minutes
core@localhost ~ $ docker commit 12c2c79f0f87 user/image
895a13e29f4a
core@localhost ~ $ docker images
REPOSITORY TAG ID CREATED SIZE
user/image latest 895a13e29f4a 6 seconds ago 16.39 kB (virtual 180.1 MB)
base latest b750fe79269d 6 months ago 24.65 kB (virtual 180.1 MB)
base ubuntu-12.10 b750fe79269d 6 months ago 24.65 kB (virtual 180.1 MB)
base ubuntu-quantal b750fe79269d 6 months ago 24.65 kB (virtual 180.1 MB)
base ubuntu-quantl b750fe79269d 6 months ago 24.65 kB (virtual 180.1 MB)
imageãä¸è¦ã«ãªãã°docker rmi
ã§åé¤ãã¾ãã
core@localhost ~ $ docker rmi 895a13e29f4a
Untagged: 895a13e29f4a
Deleted: 895a13e29f4a
Dockerfiles
imageãæ§ç¯ããcommitããæé ãDockerfilesã¨ãããã¡ã¤ã«ã«è¨è¿°ãããã¨ãã§ãã¾ãã
å
¬å¼ããã¥ã¡ã³ã
ãã©ã¼ããã
Dockerfileã®ãã©ã¼ãããã¯åç´ã§ãã
å½ä»¤ã§ã¯ã大æåã¨å°æåã¯åºå¥ããããdockerã¯Dockerfileã®å½ä»¤ãé çªã«è©ä¾¡ãã¾ãã
æåã®å½ä»¤ã¯FROM
ã§ãªããã°ãªãã¾ããã
#
ããå§ã¾ãè¡ã¯ã³ã¡ã³ãã§ãã
FROM
FROM
ã¯èµ·ç¹ã¨ãªãã¤ã¡ã¼ã¸ãæå®ãã¾ãã
FROMã¯Dockerfileã®ä¸ã§ãæåã®éã³ã¡ã³ãã®å½ä»¤ã§ãªããã°ããã¾ããã
FROM <image>
FROM <TAG>ï¼<image>
FROMã¯ãè¤æ°ã®ã¤ã¡ã¼ã¸ãä½æããããã«ãåä¸Dockerfileã®å ã§è¤æ°åè¨è¿°ãããã¨ãã§ãã¾ãã
MAINTAINER
MAINTAINER <NAME>
MAINTAINER
ã¯èè
æ
å ±ã®è¨å®ãè¡ãã¾ãã
RUN
RUN <command>
RUN
ã¯ãç¾å¨ã®ã¤ã¡ã¼ã¸ã§ä»»æã®ã³ãã³ããå®è¡ããçµæãã³ããããã¾ãã
ã³ããããããã¤ã¡ã¼ã¸ã¯ãDockerfileã®æ¬¡ã®ã¹ãããã§ä½¿ç¨ããã¾ãã
CMD
RUNå½ä»¤ã¯å®éã«ã³ãã³ããå®è¡ããçµæãã³ããããã¾ããã
ãããCMD
å½ä»¤ã¯ãã«ãæã«ã¯ä½ãå®è¡ãã¾ããã
CMDå½ä»¤ã¯ã³ã³ããèµ·åæã«ããã©ã«ãã§ã®å®è¡ã³ãã³ããæå®ãããã®ã§ãã
CMDå½ä»¤ã«ã¯æ¬¡ã®3ã¤ã®å½¢å¼ãããã¾ãã
CMD ["executable", "param1", "param2"] (like an exec, preferred form)
CMD ["param1", "param2"] (as default parameters to ENTRYPOINT)
CMD command param1 param2 (as a shell)
EXPOSE
EXPOSE
å½ä»¤ã¯ãã¤ã¡ã¼ã¸ãå®è¡ãã¦ããã¨ãã«å
¬éãããã¼ããè¨å®ãã¾ã
EXPOSE <port> [<port>...]
ENV
ENV <key> <value>
ENV
å½ä»¤ã¯ç°å¢å¤æ°è¨å®ã®
ADD
ADD
å½ä»¤ã¯SRCããæ°ãããã¡ã¤ã«ãã³ãã¼ããDESTãã¹ã§ã³ã³ããã®ãã¡ã¤ã«ã·ã¹ãã ã«è¿½å ãã¾ãã
ADD <src> <dest>
- srcãURLã§ãdestãã¹ã©ãã·ã¥ã§çµãããªãå ´åããã¡ã¤ã«ã¯URLãããã¦ã³ãã¼ããããdestã«ã³ãã¼ããã¾ã
- srcãURLã§ãdestãã¹ã©ãã·ã¥ã§çµããå ´åããã¡ã¤ã«åã¯URLããæ¨è«ããã¾ã
- srcããã£ã¬ã¯ããªã§ããå ´åããã£ã¬ã¯ããªã¼ããã¡ã¤ã«ã·ã¹ãã ã»ã¡ã¿ãã¼ã¿ãå«ãã¦ã³ãã¼ããã¾ã
- srcãgzip, bzip2,xzãªã©ã®tarã¢ã¼ã«ã¤ãã§ããå ´åãããã¯ãã£ã¬ã¯ããªã¨ãã¦å±éããã¾ã
- destãåå¨ããªãå ´åããã£ã¬ã¯ããªã¨å ±ã«ä½æããã¾ã
- æ°ãããã¡ã¤ã«ããã³ãã£ã¬ã¯ããªã¯æ¨©é 0755, uidããã³gidã0ã§ä½æããã¾ã
USER
USER
å½ä»¤ã¯ãã¤ã¡ã¼ã¸ãå®è¡ããã¨ãã«ä½¿ç¨ããã¦ã¼ã¶ã¼åã¾ãã¯UIDãè¨å®ãã¾ãã
USER daemon
WORKDIR
WORKDIR
å½ä»¤ã¯ãCMDã³ãã³ãã®ä½æ¥ãã£ã¬ã¯ããªãæå®ãã¾ãã
WORKDIR /path/to/workdir
dockerã¤ã¡ã¼ã¸ã®ãã«ã
Dockerfileã®ãããã£ã¬ã¯ããªã§docker build
ãããã¨ã§ãDockerfileã«åºã¥ãã¦ã¤ã¡ã¼ã¸ãä½æãããã¨ãã§ãã¾ãã
docker build .
-t
ãªãã·ã§ã³ã§ååãã¤ãã¦ãããæ¹ãå¾ããããããããã§ãã
docker build -t username/imagename .
Dockerfileã§redis-serverã¤ã¡ã¼ã¸ãä½æãã
Dockerfileã§ã¤ã¡ã¼ã¸ãä½æãã¦ã¿ã¾ãã
以ä¸ã®å
容ã./redis/Dockerfile
ã«ä¿åãã
Dockerfile
(redis-server)
FROM base
RUN apt-get update
RUN apt-get -y install redis-server
RUN echo "1" >> /proc/sys/vm/overcommit_memory
EXPOSE 6379
CMD ["/usr/bin/redis-server"]
docker build -t redis redis/
ã§ãã«ããã¾ãã
core@localhost ~ $ docker build -t redis redis/
Uploading context 10240 bytes
Step 1 : FROM base
---> b750fe79269d
Step 2 : RUN apt-get update
---> Running in a53ede3a27e0
Ign http://archive.ubuntu.com quantal InRelease
Hit http://archive.ubuntu.com quantal Release.gpg
Hit http://archive.ubuntu.com quantal Release
Hit http://archive.ubuntu.com quantal/main amd64 Packages
Get:1 http://archive.ubuntu.com quantal/universe amd64 Packages [5274 kB]
Get:2 http://archive.ubuntu.com quantal/multiverse amd64 Packages [131 kB]
Get:3 http://archive.ubuntu.com quantal/main Translation-en [660 kB]
Get:4 http://archive.ubuntu.com quantal/multiverse Translation-en [100 kB]
Get:5 http://archive.ubuntu.com quantal/universe Translation-en [3648 kB]
Fetched 9813 kB in 29s (329 kB/s)
Reading package lists...
---> dcedb6a66ab8
Step 3 : RUN apt-get -y install redis-server
---> Running in 0813f1e8d204
Reading package lists...
Building dependency tree...
The following extra packages will be installed:
libjemalloc1
The following NEW packages will be installed:
libjemalloc1 redis-server
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 319 kB of archives.
After this operation, 821 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu/ quantal/universe libjemalloc1 amd64 3.0.0-3 [85.9 kB]
Get:2 http://archive.ubuntu.com/ubuntu/ quantal/universe redis-server amd64 2:2.4.15-1 [233 kB]
debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (Can't locate Term/ReadLine.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.14.2 /usr/local/share/perl/5.14.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.14 /usr/share/perl/5.14 /usr/local/lib/site_perl .) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7, <> line 2.)
debconf: falling back to frontend: Teletype
dpkg-preconfigure: unable to re-open stdin:
Fetched 319 kB in 3s (101 kB/s)
Selecting previously unselected package libjemalloc1.
(Reading database ... 9893 files and directories currently installed.)
Unpacking libjemalloc1 (from .../libjemalloc1_3.0.0-3_amd64.deb) ...
Selecting previously unselected package redis-server.
Unpacking redis-server (from .../redis-server_2%3a2.4.15-1_amd64.deb) ...
Processing triggers for ureadahead ...
Setting up libjemalloc1 (3.0.0-3) ...
Setting up redis-server (2:2.4.15-1) ...
Starting redis-server: redis-server.
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place
Processing triggers for ureadahead ...
---> faf3c2058696
Step 4 : RUN echo "1" >> /proc/sys/vm/overcommit_memory
---> Running in 8a156b0deb85
---> 534829495ad6
Step 5 : EXPOSE 6379
---> Running in fe6d78cacb63
---> cb23d38bd114
Step 6 : CMD ["/usr/bin/redis-server"]
---> Running in cad2967f489a
---> e31730c0e9f0
Successfully built e31730c0e9f0
redisã¨ããååã§ã¤ã¡ã¼ã¸ãä½æã§ããã®ã§ã-d
ãªãã·ã§ã³ã§ããã¯ã°ã©ã¦ã³ãæå®ãã-p
ãªãã·ã§ã³ã§port forwardãæå®ãã¾ãã
CMD
å½ä»¤ã§redis-serverãæå®ãã¦ããã®ã§ãã³ãã³ãã¯çç¥ã§ãã¾ãã
core@localhost ~ $ docker run -d -p 6379 redis
a558ea555e65
docker inspect
ã§è©³ç´°æ
å ±ã確èªãããã¨ãã§ãã¾ãã
core@localhost ~ $ docker ps
ID IMAGE COMMAND CREATED STATUS PORTS
a558ea555e65 redis:latest /usr/bin/redis-serve 3 seconds ago Up 3 seconds 49157->6379
core@localhost ~ $ docker inspect a558ea555e65
[{
"ID": "a558ea555e65a1fe3c4562aad4344035b7249606e065e3ed25d3b46ec561292f",
"Created": "2013-10-11T04:21:48.191626933Z",
"Path": "/usr/bin/redis-server",
"Args": [],
"Config": {
"Hostname": "a558ea555e65",
"Domainname": "",
"User": "",
"Memory": 0,
"MemorySwap": 0,
"CpuShares": 0,
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"PortSpecs": [
"6379"
],
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"HOME=/",
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/usr/bin/redis-server"
],
"Dns": null,
"Image": "redis",
"Volumes": {},
"VolumesFrom": "",
"WorkingDir": "",
"Entrypoint": [],
"NetworkDisabled": false,
"Privileged": false
},
"State": {
"Running": true,
"Pid": 5104,
"ExitCode": 0,
"StartedAt": "2013-10-11T04:21:48.196375494Z",
"Ghost": false
},
"Image": "e31730c0e9f0c23a8f3ecf282a3488d1eee717a0d5f0e7ca6ff1249795ffda20",
"NetworkSettings": {
"IPAddress": "172.17.0.9",
"IPPrefixLen": 16,
"Gateway": "172.17.42.1",
"Bridge": "docker0",
"PortMapping": {
"Tcp": {
"6379": "49157"
},
"Udp": {}
}
},
"SysInitPath": "/usr/bin/docker",
"ResolvConfPath": "/etc/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/a558ea555e65a1fe3c4562aad4344035b7249606e065e3ed25d3b46ec561292f/hostname",
"HostsPath": "/var/lib/docker/containers/a558ea555e65a1fe3c4562aad4344035b7249606e065e3ed25d3b46ec561292f/hosts",
"Volumes": {},
"VolumesRW": {}
}]core@localhost ~ $
ä»ã®ã³ã³ãããç«ã¡ä¸ãã¦redis-serverã«æ¥ç¶ãã¦ã¿ã¾ãã
redis-clientãæä½ãããã®ã§ãdocker run
å®è¡æã®ã³ãã³ããä¸æ¸ããã¾ãã
core@localhost ~ $ docker run -i -t redis bash
root@5383436248fa:/# redis-cli -h 172.17.0.9 -p 6379
redis 172.17.0.9:6379>
vagrantã§private networkã®è¨å®ãè¡ã£ã¦ããã°ã
config.vm.network :private_network, ip: "192.168.33.10"
ãã¹ãOSããã§ãæ¥ç¶ã§ãã¾ãã
redis-cli -h 192.168.33.10 -p 49157
OSX -> CoreOS (vagrant) -> ã³ã³ãã ã¨ããæ§æãªã®ã§ãç´æ¥SSHæ¥ç¶ã§ãããããªã¤ã¡ã¼ã¸ãä½æããã¨ããããsshãµã¼ãã¼ãä½ãDockerfileãä½æãã¦docer build
ããã°OKã§ãã
passwordã¯é©å®å¤æ´ãã¦ãã ããã
Dockerfile
(ssh-server)
FROM base
RUN apt-get update
RUN apt-get install -y openssh-server
RUN mkdir /var/run/sshd
RUN echo 'root:password' |chpasswd
EXPOSE 22
CMD /usr/sbin/sshd -D
ã¤ã¡ã¼ã¸ããã«ããã¦ã
core@localhost ~ $ docker build -t base_ssh Dockerfiles/ssh/
ãã¼ãã確èªãã¦ã
core@localhost ~ $ docker ps
ID IMAGE COMMAND CREATED STATUS PORTS
234c6e33237d base_ssh:latest /bin/sh -c /usr/sbin 19 minutes ago Up 19 minutes 49153->22
æ¥ç¶ãã¾ã
ssh [email protected] -p 49153
éæ
dockerã§ã®ã³ã³ããæä½ã¯ãvagrant upãããããéãã«è»½ãã§ãã
ä»®æ³ãã·ã³ãç«ã¡ä¸ãã¦ã»æä½ãã¦ã»ç ´æ£ãã¦ãæ°å
¼ããªãã§ããããã«ãªãã¾ããã
ãµã¼ãã¼ç¶æ
ã®å¤æ´ãgitã®ããã«commitã§æä½ã§ããã®ã便å©ã§ãã
Dockerfileãé
å¸ãããã¨ã«ãã£ã¦ã»ããã¢ããæé ãå
¬éã§ãããã¨ãå¯è½æ§ãåºããã¾ããã