Dockerに触れる
最近はDockerで遊んでます。 Chefとか黙々やっていたのですが、気分転換にDockerを使いました。
メモ代わりに。
公式が一番
準備
git clone https://github.com/dotcloud/docker.git cd docker vagrant up
Puttyからの接続
vagrant ssh-config
putty用に鍵を生成する。 PuTTYgen -> 既存の秘密鍵の読込。
Dockerのバージョンを確認
$ docker version
Client version: 0.7.2 Go version (client): go1.2 Git commit (client): 28b162e Server version: 0.7.2 Git commit (server): 28b162e Go version (server): go1.2 Last stable version: 0.7.2
Docker イメージを検索する
Dockerには色々なイメージがあり、簡単に検索出来るサイトが存在します。
こちらから
docker search 検索したいイメージ名
$ docker search tutorial
NAME DESCRIPTION STARS OFFICIAL TRUSTED learn/tutorial 0 mzdaniel/buildbot-tutorial 0 jbarbier/tutorial1 0 odewahn/parallel_ml_tutorial 0 modolo/redis Tutorial redis 0 mhubig/echo Simple echo loop from the tutorial. 0 ivarvong/redis From the redis tutorial. Just redis-server... 0 danlucraft/postgresql Postgresql 9.3, on port 5432, un:docker, p... 0 amattn/postgresql-9.3.0 precise base, PostgreSQL 9.3.0 installed w... 0
Dockerのイメージをダウンロードする
pullすればダウンロード出来ます
$ docker pull learn/tutorial Pulling repository learn/tutorial 8dbd9e392a96: Download complete
Docker上でechoコマンドを実行する
$ docker run learn/tutorial echo "hello world" hello world
apt-getでpingコマンドをインストールする
$ docker run learn/tutorial apt-get install -y ping Reading package lists... Building dependency tree... The following NEW packages will be installed: iputils-ping 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 56.1 kB of archives. After this operation, 143 kB of additional disk space will be used. Get:1 http://archive.ubuntu.com/ubuntu/ precise/main iputils-ping amd64 3:20101006-1ubuntu1 [56.1 kB] debconf: delaying package configuration, since apt-utils is not installed Fetched 56.1 kB in 0s (69.6 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) ...
イメージをコミット
docker psで今動いているDockerの確認を行います。 そしてCONTAINER IDを利用してコミットします。
$ docker ps -l CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 0710132af978 learn/tutorial:latest apt-get install -y p 5 minutes ago Exit 0 naughty_poincare
$ docker commit 0710 learn/ping 535f88073c7d71ce1045293ebe62fccf01071e8afa56e5a6019938f25100d677
Docerkの詳細の情報を見る
$ docker inspect 3f3 [{ "ID": "3f32f9b50c7ca75ca3efdb78d9bd8291a5b5ce1c666cd6e02b889f1d083ca09b", "Created": "2013-12-23T09:56:42.372220573Z", "Path": "ping", "Args": [ "google.com" ], "Config": { "Hostname": "3f32f9b50c7c", "Domainname": "", "User": "", "Memory": 0, "MemorySwap": 0, "CpuShares": 0, "AttachStdin": false, "AttachStdout": true, "AttachStderr": true, "PortSpecs": null, "ExposedPorts": null, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": null, "Cmd": [ "ping", "google.com" ], "Dns": null, "Image": "learn/ping", "Volumes": null, "VolumesFrom": "", "WorkingDir": "", "Entrypoint": null, "NetworkDisabled": false }, "State": { "Running": false, "Pid": 0, "ExitCode": 1, "StartedAt": "2013-12-23T09:56:42.37846083Z", "FinishedAt": "2013-12-23T09:57:30.576440818Z", "Ghost": false }, "Image": "535f88073c7d71ce1045293ebe62fccf01071e8afa56e5a6019938f25100d677", "NetworkSettings": { "IPAddress": "", "IPPrefixLen": 0, "Gateway": "", "Bridge": "", "PortMapping": null, "Ports": null }, "SysInitPath": "/usr/bin/docker", "ResolvConfPath": "/etc/resolv.conf", "HostnamePath": "/var/lib/docker/containers/3f32f9b50c7ca75ca3efdb78d9bd8291a5b5ce1c666cd6e02b889f1d083ca09b/hostname", "HostsPath": "/var/lib/docker/containers/3f32f9b50c7ca75ca3efdb78d9bd8291a5b5ce1c666cd6e02b889f1d083ca09b/hosts", "Name": "/agitated_wozniak", "Driver": "aufs", "Volumes": {}, "VolumesRW": {}, "HostConfig": { "Binds": null, "ContainerIDFile": "", "LxcConf": [], "Privileged": false, "PortBindings": {}, "Links": null, "PublishAllPorts": false } }]%
アクセスやビルドは次回で。
ここからはUbuntuのお話です
初めてUbuntuを使いました。そこで日本語化のためにいくつか操作したのでメモとして残します。
wget -q https://www.ubuntulinux.jp/ubuntu-ja-archive-keyring.gpg -O- | sudo apt-key add -
wget -q https://www.ubuntulinux.jp/ubuntu-jp-ppa-keyring.gpg -O- | sudo apt-key add -
sudo wget https://www.ubuntulinux.jp/sources.list.d/precise.list -O /etc/apt/sources.list.d/ubuntu-ja.list
sudo apt-get update
sudo apt-get upgrade
vimの文字化け
sudo aptitude install language-pack-ja
export LANG=ja_JP.UTF-8
export LC_ALL=ja_JP.UTF-8
export LC_CTYPE=ja_JP.UTF-8
rbenvのインストールで躓いた点
/opt/vagrant_ruby/bin/がすでに$PATHに設定されているため、
削除する必要がある。(rbenv global 2.0.0-p247が反映されないため)