「Docker」の版間の差分
提供: Ubuntu入門
(相違点なし)
|
2014年5月27日 (火) 23:15時点における版
Docker とは、Linux用のアプリケーション実行環境のコンテナです。
読み方
- Docker
- どっかー
目次
概要
Docker
インストール
$ sudo apt-get install docker.io
設定
使い方
docker run
sudo docker.io run -i ubuntu /bin/bash
dockerのイメージを確認する
$ sudo docker.io images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE ubuntu 13.10 5e019ab7bf6d 4 weeks ago 180 MB ubuntu saucy 5e019ab7bf6d 4 weeks ago 180 MB ubuntu precise 74fe38d11401 4 weeks ago 209.6 MB ubuntu 12.04 74fe38d11401 4 weeks ago 209.6 MB ubuntu 12.10 a7cf8ae4e998 4 weeks ago 171.3 MB ubuntu quantal a7cf8ae4e998 4 weeks ago 171.3 MB ubuntu latest 99ec81b80c55 4 weeks ago 266 MB ubuntu 14.04 99ec81b80c55 4 weeks ago 266 MB ubuntu trusty 99ec81b80c55 4 weeks ago 266 MB ubuntu 13.04 316b678ddf48 4 weeks ago 169.4 MB ubuntu raring 316b678ddf48 4 weeks ago 169.4 MB ubuntu 10.04 3db9c44f4520 5 weeks ago 183 MB ubuntu lucid 3db9c44f4520 5 weeks ago 183 MB
Dockerfile
Dockerfile の例
FROM ubuntu RUN apt-get install -y nginx
docker build
docker.io build のときに、 -t オプションでイメージに名前をつけることができます。
$ sudo docker.io build . [sudo] password for kaworu: Uploading context 4.096 kB Uploading context Step 0 : FROM ubuntu ---> 99ec81b80c55 Step 1 : RUN apt-get install -y nginx ---> Running in e2d26d470085 Reading package lists... Building dependency tree... Reading state information... The following extra packages will be installed: fontconfig-config fonts-dejavu-core geoip-database libfontconfig1 libfreetype6 libgd3 libgeoip1 libjbig0 libjpeg-turbo8 libjpeg8 libtiff5 libvpx1 libx11-6 libx11-data libxau6 libxcb1 libxdmcp6 libxml2 libxpm4 libxslt1.1 nginx-common nginx-core sgml-base xml-core Suggested packages: libgd-tools geoip-bin fcgiwrap nginx-doc sgml-base-doc debhelper The following NEW packages will be installed: fontconfig-config fonts-dejavu-core geoip-database libfontconfig1 libfreetype6 libgd3 libgeoip1 libjbig0 libjpeg-turbo8 libjpeg8 libtiff5 libvpx1 libx11-6 libx11-data libxau6 libxcb1 libxdmcp6 libxml2 libxpm4 libxslt1.1 nginx nginx-common nginx-core sgml-base xml-core 0 upgraded, 25 newly installed, 0 to remove and 0 not upgraded. Need to get 5612 kB of archives. After this operation, 19.8 MB of additional disk space will be used. Get:1 http://archive.ubuntu.com/ubuntu/ trusty/main libgeoip1 amd64 1.6.0-1 [71.0 kB] Get:2 http://archive.ubuntu.com/ubuntu/ trusty/main libxau6 amd64 1:1.0.8-1 [8376 B] Get:3 http://archive.ubuntu.com/ubuntu/ trusty/main libxdmcp6 amd64 1:1.1.1-1 [12.8 kB] Get:4 http://archive.ubuntu.com/ubuntu/ trusty/main libxcb1 amd64 1.10-2ubuntu1 [38.0 kB] Get:5 http://archive.ubuntu.com/ubuntu/ trusty/main libx11-data all 2:1.6.2-1ubuntu2 [111 kB] Get:6 http://archive.ubuntu.com/ubuntu/ trusty/main libx11-6 amd64 2:1.6.2-1ubuntu2 [560 kB] Get:7 http://archive.ubuntu.com/ubuntu/ trusty/main libxml2 amd64 2.9.1+dfsg1-3ubuntu4 [571 kB] Get:8 http://archive.ubuntu.com/ubuntu/ trusty/main sgml-base all 1.26+nmu4ubuntu1 [12.5 kB] Get:9 http://archive.ubuntu.com/ubuntu/ trusty/main fonts-dejavu-core all 2.34-1ubuntu1 [1024 kB] Get:10 http://archive.ubuntu.com/ubuntu/ trusty/main fontconfig-config all 2.11.0-0ubuntu4 [47.3 kB] Get:11 http://archive.ubuntu.com/ubuntu/ trusty/main libfreetype6 amd64 2.5.2-1ubuntu2 [305 kB] Get:12 http://archive.ubuntu.com/ubuntu/ trusty/main libfontconfig1 amd64 2.11.0-0ubuntu4 [123 kB] Get:13 http://archive.ubuntu.com/ubuntu/ trusty/main libjpeg-turbo8 amd64 1.3.0-0ubuntu2 [104 kB] Get:14 http://archive.ubuntu.com/ubuntu/ trusty/main libjpeg8 amd64 8c-2ubuntu8 [2194 B] Get:15 http://archive.ubuntu.com/ubuntu/ trusty/main libjbig0 amd64 2.0-2ubuntu4 [25.9 kB] Get:16 http://archive.ubuntu.com/ubuntu/ trusty/main libtiff5 amd64 4.0.3-7 [142 kB] Get:17 http://archive.ubuntu.com/ubuntu/ trusty/main libvpx1 amd64 1.3.0-2 [556 kB] Get:18 http://archive.ubuntu.com/ubuntu/ trusty/main libxpm4 amd64 1:3.5.10-1 [38.3 kB] Get:19 http://archive.ubuntu.com/ubuntu/ trusty/main libgd3 amd64 2.1.0-3 [147 kB] Get:20 http://archive.ubuntu.com/ubuntu/ trusty/main libxslt1.1 amd64 1.1.28-2build1 [145 kB] Get:21 http://archive.ubuntu.com/ubuntu/ trusty/main geoip-database all 20140313-1 [1196 kB] Get:22 http://archive.ubuntu.com/ubuntu/ trusty/main xml-core all 0.13+nmu2 [23.3 kB] Get:23 http://archive.ubuntu.com/ubuntu/ trusty/main nginx-common all 1.4.6-1ubuntu3 [18.1 kB] Get:24 http://archive.ubuntu.com/ubuntu/ trusty/main nginx-core amd64 1.4.6-1ubuntu3 [324 kB] Get:25 http://archive.ubuntu.com/ubuntu/ trusty/main nginx all 1.4.6-1ubuntu3 [5586 B] 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: (This frontend requires a controlling tty.) debconf: falling back to frontend: Teletype dpkg-preconfigure: unable to re-open stdin: Fetched 5612 kB in 46s (121 kB/s) Selecting previously unselected package libgeoip1:amd64. (Reading database ... 11518 files and directories currently installed.) Preparing to unpack .../libgeoip1_1.6.0-1_amd64.deb ... Unpacking libgeoip1:amd64 (1.6.0-1) ... Selecting previously unselected package libxau6:amd64. Preparing to unpack .../libxau6_1%3a1.0.8-1_amd64.deb ... Unpacking libxau6:amd64 (1:1.0.8-1) ... Selecting previously unselected package libxdmcp6:amd64. Preparing to unpack .../libxdmcp6_1%3a1.1.1-1_amd64.deb ... Unpacking libxdmcp6:amd64 (1:1.1.1-1) ... Selecting previously unselected package libxcb1:amd64. Preparing to unpack .../libxcb1_1.10-2ubuntu1_amd64.deb ... Unpacking libxcb1:amd64 (1.10-2ubuntu1) ... Selecting previously unselected package libx11-data. Preparing to unpack .../libx11-data_2%3a1.6.2-1ubuntu2_all.deb ... Unpacking libx11-data (2:1.6.2-1ubuntu2) ... Selecting previously unselected package libx11-6:amd64. Preparing to unpack .../libx11-6_2%3a1.6.2-1ubuntu2_amd64.deb ... Unpacking libx11-6:amd64 (2:1.6.2-1ubuntu2) ... Selecting previously unselected package libxml2:amd64. Preparing to unpack .../libxml2_2.9.1+dfsg1-3ubuntu4_amd64.deb ... Unpacking libxml2:amd64 (2.9.1+dfsg1-3ubuntu4) ... Selecting previously unselected package sgml-base. Preparing to unpack .../sgml-base_1.26+nmu4ubuntu1_all.deb ... Unpacking sgml-base (1.26+nmu4ubuntu1) ... Selecting previously unselected package fonts-dejavu-core. Preparing to unpack .../fonts-dejavu-core_2.34-1ubuntu1_all.deb ... Unpacking fonts-dejavu-core (2.34-1ubuntu1) ... Selecting previously unselected package fontconfig-config. Preparing to unpack .../fontconfig-config_2.11.0-0ubuntu4_all.deb ... Unpacking fontconfig-config (2.11.0-0ubuntu4) ... Selecting previously unselected package libfreetype6:amd64. Preparing to unpack .../libfreetype6_2.5.2-1ubuntu2_amd64.deb ... Unpacking libfreetype6:amd64 (2.5.2-1ubuntu2) ... Selecting previously unselected package libfontconfig1:amd64. Preparing to unpack .../libfontconfig1_2.11.0-0ubuntu4_amd64.deb ... Unpacking libfontconfig1:amd64 (2.11.0-0ubuntu4) ... Selecting previously unselected package libjpeg-turbo8:amd64. Preparing to unpack .../libjpeg-turbo8_1.3.0-0ubuntu2_amd64.deb ... Unpacking libjpeg-turbo8:amd64 (1.3.0-0ubuntu2) ... Selecting previously unselected package libjpeg8:amd64. Preparing to unpack .../libjpeg8_8c-2ubuntu8_amd64.deb ... Unpacking libjpeg8:amd64 (8c-2ubuntu8) ... Selecting previously unselected package libjbig0:amd64. Preparing to unpack .../libjbig0_2.0-2ubuntu4_amd64.deb ... Unpacking libjbig0:amd64 (2.0-2ubuntu4) ... Selecting previously unselected package libtiff5:amd64. Preparing to unpack .../libtiff5_4.0.3-7_amd64.deb ... Unpacking libtiff5:amd64 (4.0.3-7) ... Selecting previously unselected package libvpx1:amd64. Preparing to unpack .../libvpx1_1.3.0-2_amd64.deb ... Unpacking libvpx1:amd64 (1.3.0-2) ... Selecting previously unselected package libxpm4:amd64. Preparing to unpack .../libxpm4_1%3a3.5.10-1_amd64.deb ... Unpacking libxpm4:amd64 (1:3.5.10-1) ... Selecting previously unselected package libgd3:amd64. Preparing to unpack .../libgd3_2.1.0-3_amd64.deb ... Unpacking libgd3:amd64 (2.1.0-3) ... Selecting previously unselected package libxslt1.1:amd64. Preparing to unpack .../libxslt1.1_1.1.28-2build1_amd64.deb ... Unpacking libxslt1.1:amd64 (1.1.28-2build1) ... Selecting previously unselected package geoip-database. Preparing to unpack .../geoip-database_20140313-1_all.deb ... Unpacking geoip-database (20140313-1) ... Selecting previously unselected package xml-core. Preparing to unpack .../xml-core_0.13+nmu2_all.deb ... Unpacking xml-core (0.13+nmu2) ... Selecting previously unselected package nginx-common. Preparing to unpack .../nginx-common_1.4.6-1ubuntu3_all.deb ... Unpacking nginx-common (1.4.6-1ubuntu3) ... Selecting previously unselected package nginx-core. Preparing to unpack .../nginx-core_1.4.6-1ubuntu3_amd64.deb ... Unpacking nginx-core (1.4.6-1ubuntu3) ... Selecting previously unselected package nginx. Preparing to unpack .../nginx_1.4.6-1ubuntu3_all.deb ... Unpacking nginx (1.4.6-1ubuntu3) ... Processing triggers for ureadahead (0.100.0-16) ... Setting up libgeoip1:amd64 (1.6.0-1) ... Setting up libxau6:amd64 (1:1.0.8-1) ... Setting up libxdmcp6:amd64 (1:1.1.1-1) ... Setting up libxcb1:amd64 (1.10-2ubuntu1) ... Setting up libx11-data (2:1.6.2-1ubuntu2) ... Setting up libx11-6:amd64 (2:1.6.2-1ubuntu2) ... Setting up libxml2:amd64 (2.9.1+dfsg1-3ubuntu4) ... Setting up sgml-base (1.26+nmu4ubuntu1) ... Setting up fonts-dejavu-core (2.34-1ubuntu1) ... Setting up fontconfig-config (2.11.0-0ubuntu4) ... Setting up libfreetype6:amd64 (2.5.2-1ubuntu2) ... Setting up libfontconfig1:amd64 (2.11.0-0ubuntu4) ... Setting up libjpeg-turbo8:amd64 (1.3.0-0ubuntu2) ... Setting up libjpeg8:amd64 (8c-2ubuntu8) ... Setting up libjbig0:amd64 (2.0-2ubuntu4) ... Setting up libtiff5:amd64 (4.0.3-7) ... Setting up libvpx1:amd64 (1.3.0-2) ... Setting up libxpm4:amd64 (1:3.5.10-1) ... Setting up libgd3:amd64 (2.1.0-3) ... Setting up libxslt1.1:amd64 (1.1.28-2build1) ... Setting up geoip-database (20140313-1) ... Setting up xml-core (0.13+nmu2) ... Setting up nginx-common (1.4.6-1ubuntu3) ... Processing triggers for ureadahead (0.100.0-16) ... Setting up nginx-core (1.4.6-1ubuntu3) ... invoke-rc.d: policy-rc.d denied execution of start. Setting up nginx (1.4.6-1ubuntu3) ... Processing triggers for libc-bin (2.19-0ubuntu6) ... Processing triggers for sgml-base (1.26+nmu4ubuntu1) ... ---> f5c6635a7494 Successfully built f5c6635a7494 Removing intermediate container e2d26d470085
docker tag
docker build で作成したイメージは名前がないので、 docker tag でつけます。
$ sudo docker.io tag f5c6635a7494 nginx $ sudo docker.io images|head -2 REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE nginx latest f5c6635a7494 17 minutes ago 284.4 MB
docker build のときに-tオプションで名前を指定することもできます。
イメージを確認する
$ sudo docker.io images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE <none> <none> f5c6635a7494 16 minutes ago 284.4 MB ubuntu 13.10 5e019ab7bf6d 4 weeks ago 180 MB ubuntu saucy 5e019ab7bf6d 4 weeks ago 180 MB ubuntu 12.04 74fe38d11401 4 weeks ago 209.6 MB ubuntu precise 74fe38d11401 4 weeks ago 209.6 MB ubuntu quantal a7cf8ae4e998 4 weeks ago 171.3 MB ubuntu 12.10 a7cf8ae4e998 4 weeks ago 171.3 MB ubuntu trusty 99ec81b80c55 4 weeks ago 266 MB ubuntu 14.04 99ec81b80c55 4 weeks ago 266 MB ubuntu latest 99ec81b80c55 4 weeks ago 266 MB ubuntu 13.04 316b678ddf48 4 weeks ago 169.4 MB ubuntu raring 316b678ddf48 4 weeks ago 169.4 MB ubuntu 10.04 3db9c44f4520 5 weeks ago 183 MB ubuntu lucid 3db9c44f4520 5 weeks ago 183 MB
dockerでmemcachedを動かす
Dockerfile.memcached
FROM ubuntu RUN apt-get install -y memcached ENTRYPOINT ["memcached"] USER daemon EXPOSE 11211
イメージを作成します。
sudo docker.io build -t memcached - < Dockerfile.memcached
コンテナを起動します。
sudo docker.io run -d -p 11211 memcached
11211:11211と指定すれば、ホスト側から11211でアクセスできます。
ps で11211にアクセスするためのポートが調べられます。
$ sudo docker.io ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7b58125ba29d memcached:latest memcached 3 minutes ago Up 3 minutes 0.0.0.0:49156->11211/tcp sick_brattain
ローカルホストの 49156 にアクセスすることで、コンテナの11211のmemcachedに接続できます。
telnet localhost 49156
コンテナを終了させるには、docker.io psで調べられるコンテナIDを指定します。
sudo docker.io stop 7b58125ba29d