21
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

coreosとDocker

Posted at

#参考情報

Dokcer

http://www.infoq.com/jp/articles/docker-containers
http://n8.hatenablog.com/entry/2013/08/15/164643

CoreOS

$ git clone https://github.com/coreos/coreos-vagrant/ coreos
$ cd coreos
$ vagrant up

$ vagrant list
ALL:
39c236d1-077d-4afe-a537-2aba6cdd160f: coreos-vagrant_default_1382366707 (Linux 2.6 (64 bit))
RUNNING:
39c236d1-077d-4afe-a537-2aba6cdd160f: coreos-vagrant_default_1382366707 (Linux 2.6 (64 bit))
$ vagrant ssh
Last login: Mon Oct 21 14:45:28 UTC 2013 from 10.0.2.2 on ssh
   ______                ____  _____
  / ____/___  ________  / __ \/ ___/
 / /   / __ \/ ___/ _ \/ / / /\__ \
/ /___/ /_/ / /  /  __/ /_/ /___/ /
\____/\____/_/   \___/\____//____/

core@localhost ~ $ uname -a
Linux localhost 3.10.10+ #1 SMP Tue Oct 15 01:37:23 UTC 2013 x86_64 Intel(R) Core(TM) i5-4250U CPU @ 1.30GHz GenuineIntel GNU/Linux
core@localhost ~ $ cat /etc/gentoo-release 
CoreOS release 106.0.0
core@localhost ~ $ ps axu | grep dock
root       430  0.0  0.7 273760  7824 ?        Ssl  14:45   0:00 /usr/bin/docker -d
core       656  0.0  0.0   4364   648 pts/0    S+   14:46   0:00 grep --colour=auto dock

###coreosにはDockerがインストールされている

core@localhost ~ $ sudo netstat -nlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:7001          0.0.0.0:*               LISTEN      383/etcd            
tcp        0      0 0.0.0.0:16385           0.0.0.0:*               LISTEN      -                   
tcp6       0      0 :::22                   :::*                    LISTEN      1/init              
tcp6       0      0 :::4001                 :::*                    LISTEN      383/etcd            
udp        0      0 0.0.0.0:8472            0.0.0.0:*                           -                   
raw6       0      0 :::58                   :::*                    7           347/dhcpcd          
Active UNIX domain sockets (only servers)
Proto RefCnt Flags       Type       State         I-Node   PID/Program name     Path
unix  2      [ ACC ]     STREAM     LISTENING     13862    347/dhcpcd           /var/run/dhcpcd.sock
unix  2      [ ACC ]     STREAM     LISTENING     9013     1/init               /run/systemd/private
unix  2      [ ACC ]     STREAM     LISTENING     9038     1/init               /run/systemd/journal/stdout
unix  2      [ ACC ]     STREAM     LISTENING     13669    1/init               /var/run/dbus/system_bus_socket
unix  2      [ ACC ]     SEQPACKET  LISTENING     9325     1/init               /run/udev/control
unix  2      [ ACC ]     STREAM     LISTENING     14833    430/docker           /var/run/docker.sock
core@localhost ~ $ docker images
REPOSITORY          TAG                 ID                  CREATED             SIZE
core@localhost ~ $ docker pull base
Pulling repository base
b750fe79269d: Download complete
27cf78414709: Download complete
core@localhost ~ $ docker images
REPOSITORY          TAG                 ID                  CREATED             SIZE
base                latest              b750fe79269d        7 months ago        24.65 kB (virtual 180.1 MB)
base                ubuntu-12.10        b750fe79269d        7 months ago        24.65 kB (virtual 180.1 MB)
base                ubuntu-quantal      b750fe79269d        7 months ago        24.65 kB (virtual 180.1 MB)
base                ubuntu-quantl       b750fe79269d        7 months ago        24.65 kB (virtual 180.1 MB)
core@localhost ~ $ docker run base /bin/echo hello world
hello world
core@localhost ~ $ docker ps -a
ID                  IMAGE               COMMAND                CREATED             STATUS              PORTS
5885de2407f7        base:latest         /bin/echo hello worl   14 seconds ago      Exit 0                                  
core@localhost ~ $ docker rm 5885de2407f7
5885de2407f7
core@localhost ~ $ docker ps -a
ID                  IMAGE               COMMAND             CREATED             STATUS              PORTS
docker run -i -t base /bin/bash
2013/10/22 03:21:44 Error: Error starting container 2563f1146cab: fork/exec /usr/sbin/lxc-start: operation not permitted

***1回目は失敗する

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

root@ef48665eb7a8:/# apt-get update
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 21s (446 kB/s)                                                                                         
Reading package lists... Done

root@ef48665eb7a8:/# apt-get install nginx
Reading package lists... Done
Building dependency tree... Done
The following extra packages will be installed:
  geoip-database libfreetype6 libgcrypt11 libgd2-noxpm libgeoip1 libgpg-error0 libjpeg-turbo8 libjpeg8 libxml2 libxslt1.1
  nginx-common nginx-full sgml-base xml-core
Suggested packages:
  rng-tools libgd-tools geoip-bin sgml-base-doc debhelper
The following NEW packages will be installed:
  geoip-database libfreetype6 libgcrypt11 libgd2-noxpm libgeoip1 libgpg-error0 libjpeg-turbo8 libjpeg8 libxml2 libxslt1.1
  nginx nginx-common nginx-full sgml-base xml-core
0 upgraded, 15 newly installed, 0 to remove and 0 not upgraded.
Need to get 6044 kB of archives.
After this operation, 14.2 MB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get:1 http://archive.ubuntu.com/ubuntu/ quantal/main libgpg-error0 amd64 1.10-3.1ubuntu1 [14.7 kB]
Get:2 http://archive.ubuntu.com/ubuntu/ quantal/main libgcrypt11 amd64 1.5.0-3ubuntu1 [279 kB]
Get:3 http://archive.ubuntu.com/ubuntu/ quantal/main libgeoip1 amd64 1.4.8+dfsg-4 [103 kB]
Get:4 http://archive.ubuntu.com/ubuntu/ quantal/main libfreetype6 amd64 2.4.10-0ubuntu1 [344 kB]
Get:5 http://archive.ubuntu.com/ubuntu/ quantal/main libjpeg-turbo8 amd64 1.2.1-0ubuntu2 [114 kB]                         
Get:6 http://archive.ubuntu.com/ubuntu/ quantal/main libxml2 amd64 2.8.0+dfsg1-5ubuntu2 [679 kB]                          
Get:7 http://archive.ubuntu.com/ubuntu/ quantal/main libxslt1.1 amd64 1.1.26-14 [168 kB]                                  
Get:8 http://archive.ubuntu.com/ubuntu/ quantal/main libjpeg8 amd64 8c-2ubuntu7 [2112 B]                                  
Get:9 http://archive.ubuntu.com/ubuntu/ quantal/main libgd2-noxpm amd64 2.0.36~rc1~dfsg-6ubuntu3 [201 kB]                 
Get:10 http://archive.ubuntu.com/ubuntu/ quantal/main geoip-database all 20120609-1 [3698 kB]                             
Get:11 http://archive.ubuntu.com/ubuntu/ quantal/universe nginx-common all 1.2.1-2.2 [18.7 kB]                            
Get:12 http://archive.ubuntu.com/ubuntu/ quantal/universe nginx-full amd64 1.2.1-2.2 [381 kB]                             
Get:13 http://archive.ubuntu.com/ubuntu/ quantal/universe nginx all 1.2.1-2.2 [7494 B]                                    
Get:14 http://archive.ubuntu.com/ubuntu/ quantal/main sgml-base all 1.26+nmu3ubuntu1 [11.5 kB]                            
Get:15 http://archive.ubuntu.com/ubuntu/ quantal/main xml-core all 0.13+nmu1 [23.0 kB]                                    
Fetched 6044 kB in 20s (298 kB/s)                                                                                         
Selecting previously unselected package libgpg-error0:amd64.
(Reading database ... 9893 files and directories currently installed.)
Unpacking libgpg-error0:amd64 (from .../libgpg-error0_1.10-3.1ubuntu1_amd64.deb) ...
Selecting previously unselected package libgcrypt11:amd64.
Unpacking libgcrypt11:amd64 (from .../libgcrypt11_1.5.0-3ubuntu1_amd64.deb) ...
Selecting previously unselected package libgeoip1:amd64.
Unpacking libgeoip1:amd64 (from .../libgeoip1_1.4.8+dfsg-4_amd64.deb) ...
Selecting previously unselected package libfreetype6:amd64.
Unpacking libfreetype6:amd64 (from .../libfreetype6_2.4.10-0ubuntu1_amd64.deb) ...
Selecting previously unselected package libjpeg-turbo8:amd64.
Unpacking libjpeg-turbo8:amd64 (from .../libjpeg-turbo8_1.2.1-0ubuntu2_amd64.deb) ...
Selecting previously unselected package libxml2:amd64.
Unpacking libxml2:amd64 (from .../libxml2_2.8.0+dfsg1-5ubuntu2_amd64.deb) ...
Selecting previously unselected package libxslt1.1:amd64.
Unpacking libxslt1.1:amd64 (from .../libxslt1.1_1.1.26-14_amd64.deb) ...
Selecting previously unselected package libjpeg8:amd64.
Unpacking libjpeg8:amd64 (from .../libjpeg8_8c-2ubuntu7_amd64.deb) ...
Selecting previously unselected package libgd2-noxpm:amd64.
Unpacking libgd2-noxpm:amd64 (from .../libgd2-noxpm_2.0.36~rc1~dfsg-6ubuntu3_amd64.deb) ...
Selecting previously unselected package geoip-database.
Unpacking geoip-database (from .../geoip-database_20120609-1_all.deb) ...
Selecting previously unselected package nginx-common.
Unpacking nginx-common (from .../nginx-common_1.2.1-2.2_all.deb) ...
Selecting previously unselected package nginx-full.
Unpacking nginx-full (from .../nginx-full_1.2.1-2.2_amd64.deb) ...
Selecting previously unselected package nginx.
Unpacking nginx (from .../nginx_1.2.1-2.2_all.deb) ...
Selecting previously unselected package sgml-base.
Unpacking sgml-base (from .../sgml-base_1.26+nmu3ubuntu1_all.deb) ...
Selecting previously unselected package xml-core.
Unpacking xml-core (from .../xml-core_0.13+nmu1_all.deb) ...
Processing triggers for ureadahead ...
Setting up libgpg-error0:amd64 (1.10-3.1ubuntu1) ...
Setting up libgcrypt11:amd64 (1.5.0-3ubuntu1) ...
Setting up libgeoip1:amd64 (1.4.8+dfsg-4) ...
Setting up libfreetype6:amd64 (2.4.10-0ubuntu1) ...
Setting up libjpeg-turbo8:amd64 (1.2.1-0ubuntu2) ...
Setting up libxml2:amd64 (2.8.0+dfsg1-5ubuntu2) ...
Setting up libxslt1.1:amd64 (1.1.26-14) ...
Setting up libjpeg8:amd64 (8c-2ubuntu7) ...
Setting up libgd2-noxpm:amd64 (2.0.36~rc1~dfsg-6ubuntu3) ...
Setting up geoip-database (20120609-1) ...
Setting up nginx-common (1.2.1-2.2) ...
Setting up sgml-base (1.26+nmu3ubuntu1) ...
Updating the super catalog...
Setting up xml-core (0.13+nmu1) ...
update-catalog: Suppressing action on super catalog. Invoking trigger instead.
update-catalog: Please rebuild the package being set up with a version of debhelper fixing #477751.
Processing triggers for ureadahead ...
Setting up nginx-full (1.2.1-2.2) ...
Setting up nginx (1.2.1-2.2) ...
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place
Processing triggers for sgml-base ...
Updating the super catalog...


nginxはデーモンなのでdockerで起動するとすぐ終了してしまうため、設定ファイルでデーモンを無効化

# cat /etc/nginx/nginx.conf 
user www-data;
worker_processes 4;
pid /var/run/nginx.pid;
daemon off;

root@ef48665eb7a8:/# exit
exit

core@localhost ~ $ docker ps -a
ID                  IMAGE               COMMAND             CREATED              STATUS              PORTS
ef48665eb7a8        base:latest         /bin/bash           About a minute ago   Exit 0                                  
2563f1146cab        base:latest         /bin/bash           About a minute ago   Exit 0                                  

core@localhost ~ $ docker commit ef48665eb7a8 masanara/nginx
3c50e4a0b8fb

core@localhost ~ $ docker images
REPOSITORY          TAG                 ID                  CREATED             SIZE
masanara/nginx      latest              3c50e4a0b8fb        5 seconds ago       116.9 MB (virtual 297 MB)
base                latest              b750fe79269d        7 months ago        24.65 kB (virtual 180.1 MB)
base                ubuntu-12.10        b750fe79269d        7 months ago        24.65 kB (virtual 180.1 MB)
base                ubuntu-quantal      b750fe79269d        7 months ago        24.65 kB (virtual 180.1 MB)
base                ubuntu-quantl       b750fe79269d        7 months ago        24.65 kB (virtual 180.1 MB)

###イメージ化したnginxコンテナを起動

core@localhost ~ $ docker run -d -p 80 masanara/nginx /usr/sbin/nginx
c2b27f7b360c
core@localhost ~ $ docker run -d -p 80 masanara/nginx /usr/sbin/nginx
e7667fa45d8d
core@localhost ~ $ docker run -d -p 80 masanara/nginx /usr/sbin/nginx
a6dbdfa710bf
core@localhost ~ $ docker run -d -p 80 masanara/nginx /usr/sbin/nginx
52048301428c
core@localhost ~ $ docker ps 
ID                  IMAGE                   COMMAND             CREATED             STATUS              PORTS
52048301428c        masanara/nginx:latest   /usr/sbin/nginx     3 seconds ago       Up 3 seconds        49172->80           
a6dbdfa710bf        masanara/nginx:latest   /usr/sbin/nginx     4 seconds ago       Up 4 seconds        49171->80           
e7667fa45d8d        masanara/nginx:latest   /usr/sbin/nginx     5 seconds ago       Up 4 seconds        49170->80           
c2b27f7b360c        masanara/nginx:latest   /usr/sbin/nginx     6 seconds ago       Up 5 seconds        49169->80    

21
20
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
21
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?