[開発] DockerとDocker Composeって何よ?

Linux上のシンプルで軽量な仮想環境(コンテナ)
Guest OSが不要な分VMよりも速い

Azure上のUbuntuDockerを入れる
rootユーザでログイン
| user1@VM01:~$ sudo su
| root@VM01:/home/user1#

最新のDockerパッケージをインストールする
| root@VM01:/home/user1# curl -fsSL https://get.docker.com/ | sh
| apparmor is enabled in the kernel and apparmor utils were already installed
| + sh -c apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-keys {key}
| Executing: /tmp/tmp.{address}/gpg.1.sh --keyserver
| hkp://ha.pool.sks-keyservers.net:80
| --recv-keys
| {key}
| gpg: requesting key {key} from hkp server ha.pool.sks-keyservers.net
| gpg: key {key}: public key "Docker Release Tool (releasedocker) " imported
| gpg: Total number processed: 1
| gpg: imported: 1 (RSA: 1)
| + break
| + sh -c apt-key adv -k {key} >/dev/null
| + sh -c mkdir -p /etc/apt/sources.list.d
| + dpkg --print-architecture
| + sh -c echo deb \[arch=amd64\] https://apt.dockerproject.org/repo ubuntu-xenial main > /etc/apt/sources.list.d/docker.list
| + sh -c sleep 3; apt-get update; apt-get install -y -q docker-engine
| Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [94.5 kB]
| Hit:2 http://azure.archive.ubuntu.com/ubuntu xenial InRelease
| Get:3 http://azure.archive.ubuntu.com/ubuntu xenial-updates InRelease [95.7 kB]
| Hit:4 http://azure.archive.ubuntu.com/ubuntu xenial-backports InRelease
| Get:5 http://download.virtualbox.org/virtualbox/debian xenial InRelease [7,894 B]
| Get:6 http://security.ubuntu.com/ubuntu xenial-security/main Sources [42.3 kB]
| Get:7 http://security.ubuntu.com/ubuntu xenial-security/universe Sources [10.1 kB]
| Get:8 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages [152 kB]
| Get:9 http://security.ubuntu.com/ubuntu xenial-security/main Translation-en [62.4 kB]
| Get:10 https://apt.dockerproject.org/repo ubuntu-xenial InRelease [30.2 kB]
| Get:11 http://security.ubuntu.com/ubuntu xenial-security/universe amd64 Packages [44.4 kB]
| Get:12 http://security.ubuntu.com/ubuntu xenial-security/universe Translation-en [26.7 kB]
| Get:13 http://azure.archive.ubuntu.com/ubuntu xenial-updates/main Sources [192 kB]
| Get:14 http://azure.archive.ubuntu.com/ubuntu xenial-updates/universe Sources [97.2 kB]
| Get:15 http://azure.archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [394 kB]
| Get:16 http://azure.archive.ubuntu.com/ubuntu xenial-updates/main Translation-en [150 kB]
| Get:17 http://azure.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [332 kB]
| Get:18 http://azure.archive.ubuntu.com/ubuntu xenial-updates/universe Translation-en [115 kB]
| Ign:5 http://download.virtualbox.org/virtualbox/debian xenial InRelease
| Get:19 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages [2,313 B]
| Fetched 1,848 kB in 1s (1,165 kB/s)
| Reading package lists... Done
| W: GPG error: http://download.virtualbox.org/virtualbox/debian xenial InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY {key}
| W: The repository 'http://download.virtualbox.org/virtualbox/debian xenial InRelease' is not signed.
| N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
| N: See apt-secure(8) manpage for repository creation and user configuration details.
| Reading package lists...
| Building dependency tree...
| Reading state information...
| The following additional packages will be installed:
| aufs-tools cgroupfs-mount libltdl7
| Suggested packages:
| mountall
| The following NEW packages will be installed:
| aufs-tools cgroupfs-mount docker-engine libltdl7
| 0 upgraded, 4 newly installed, 0 to remove and 11 not upgraded.
| Need to get 19.5 MB/19.6 MB of archives.
| After this operation, 102 MB of additional disk space will be used.
| Get:1 http://azure.archive.ubuntu.com/ubuntu xenial/universe amd64 cgroupfs-mount all 1.2 [4,970 B]
| Get:2 http://azure.archive.ubuntu.com/ubuntu xenial/main amd64 libltdl7 amd64 2.4.6-0.1 [38.3 kB]
| Get:3 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 docker-engine amd64 1.12.1-0~xenial [19.5 MB]
| Fetched 19.5 MB in 1s (12.5 MB/s)
| Selecting previously unselected package aufs-tools.
| (Reading database ... 85920 files and directories currently installed.)
| Preparing to unpack .../aufs-tools_1%3a{address}ubuntu1_amd64.deb ...
| Unpacking aufs-tools (1:{address}ubuntu1) ...
| Selecting previously unselected package cgroupfs-mount.
| Preparing to unpack .../cgroupfs-mount_1.2_all.deb ...
| Unpacking cgroupfs-mount (1.2) ...
| Selecting previously unselected package libltdl7:amd64.
| Preparing to unpack .../libltdl7_2.4.6-0.1_amd64.deb ...
| Unpacking libltdl7:amd64 (2.4.6-0.1) ...
| Selecting previously unselected package docker-engine.
| Preparing to unpack .../docker-engine_1.12.1-0~xenial_amd64.deb ...
| Unpacking docker-engine (1.12.1-0~xenial) ...
| Processing triggers for libc-bin (2.23-0ubuntu3) ...
| Processing triggers for man-db (2.7.5-1) ...
| Processing triggers for ureadahead (0.100.0-19) ...
| Processing triggers for systemd (229-4ubuntu8) ...
| Setting up aufs-tools (1:{address}ubuntu1) ...
| Setting up cgroupfs-mount (1.2) ...
| Setting up libltdl7:amd64 (2.4.6-0.1) ...
| Setting up docker-engine (1.12.1-0~xenial) ...
| sent invalidate(passwd) request, exiting
| sent invalidate(group) request, exiting
| sent invalidate(group) request, exiting
| Processing triggers for libc-bin (2.23-0ubuntu3) ...
| Processing triggers for systemd (229-4ubuntu8) ...
| Processing triggers for ureadahead (0.100.0-19) ...
| + sh -c docker version
| Client:
| Version: 1.12.1
| API version: 1.24
| Go version: go1.6.3
| Git commit: 23cf638
| Built: Thu Aug 18 05:33:38 2016
| OS/Arch: linux/amd64
|
| Server:
| Version: 1.12.1
| API version: 1.24
| Go version: go1.6.3
| Git commit: 23cf638
| Built: Thu Aug 18 05:33:38 2016
| OS/Arch: linux/amd64
|
| If you would like to use Docker as a non-root user, you should now consider
| adding your user to the "docker" group with something like:
|
| sudo usermod -aG docker your-user
|
| Remember that you will have to log out and back in for this to take effect!
|
| root@VM01:/home/user1#

一般ユーザに"docker"グループの追加
| root@VM01:/home/user1# gpasswd -a user1 docker
| Adding user user1 to group docker
| sent invalidate(passwd) request, exiting
| sent invalidate(group) request, exiting
| sent invalidate(group) request, exiting
| root@VM01:/home/user1#

一般ユーザで再度ログインして、hello-worldを実行する
| root@VM01:/home/user1#
| root@VM01:/home/user1# su user1
| user1@VM01:~$ docker run hello-world
| Unable to find image 'hello-world:latest' locally
| latest: Pulling from library/hello-world
| c04b14da8d14: Pull complete
| Digest: sha256:{sth}
| Status: Downloaded newer image for hello-world:latest
|
| Hello from Docker!
| This message shows that your installation appears to be working correctly.
|
| To generate this message, Docker took the following steps:
| 1. The Docker client contacted the Docker daemon.
| 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
| 3. The Docker daemon created a new container from that image which runs the
| executable that produces the output you are currently reading.
| 4. The Docker daemon streamed that output to the Docker client, which sent it
| to your terminal.
|
| To try something more ambitious, you can run an Ubuntu container with:
| $ docker run -it ubuntu bash
|
| Share images, automate workflows, and more with a free Docker Hub account:
| https://hub.docker.com
|
| For more examples and ideas, visit:
| https://docs.docker.com/engine/userguide/
|
| user1@VM01:~$

Dockerが起動していない時
sudo service docker start

Azure上のUbuntuにDocker Composeを入れる

Docker compose とは、
複数のコンテナから成るサービスを構築・実行する手順を自動的にし、管理を容易にする機能
compose ファイルを用意してコマンドを1 回実行することで、
そのファイルから設定を読み込んですべてのコンテナサービスを起動することができるようになる

https://docs.docker.com/compose/install/
https://docs.docker.com/engine/installation/linux/ubuntulinux/

カーネルのバージョン確認
| user1@VM01:~$ uname -r
| 4.4.0-38-generic

ユーザ切り替え
user1@VM01:~$ sudo su

アップデート
| root@VM01:/home/user1# sudo apt-get update
| Hit:1 http://azure.archive.ubuntu.com/ubuntu xenial InRelease
| Get:2 http://azure.archive.ubuntu.com/ubuntu xenial-updates InRelease [95.7 kB]
| Hit:3 http://security.ubuntu.com/ubuntu xenial-security InRelease
| Hit:4 http://azure.archive.ubuntu.com/ubuntu xenial-backports InRelease
| Get:5 http://download.virtualbox.org/virtualbox/debian xenial InRelease [7,894 B]
| Hit:6 https://apt.dockerproject.org/repo ubuntu-xenial InRelease
| Ign:5 http://download.virtualbox.org/virtualbox/debian xenial InRelease
| Fetched 104 kB in 1s (103 kB/s)
| Reading package lists... Done
| W: GPG error: http://download.virtualbox.org/virtualbox/debian xenial InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY {key}
| W: The repository 'http://download.virtualbox.org/virtualbox/debian xenial InRelease' is not signed.
| N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
| N: See apt-secure(8) manpage for repository creation and user configuration details.

CA Certificatesのインストール
| root@VM01:/home/user1# sudo apt-get install apt-transport-https ca-certificates
| Reading package lists... Done
| Building dependency tree
| Reading state information... Done
| ca-certificates is already the newest version (20160104ubuntu1).
| apt-transport-https is already the newest version (1.2.12~ubuntu16.04.1).
| 0 upgraded, 0 newly installed, 0 to remove and 11 not upgraded.
| root@VM01:/home/user1#

GPG鍵の追加
| root@VM01:/home/user1# sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
| Executing: /tmp/tmp.{address}/gpg.1.sh --keyserver
| hkp://p80.pool.sks-keyservers.net:80
| --recv-keys
| 58118E89F3A912897C070ADBF76221572C52609D
| gpg: requesting key 2C52609D from hkp server p80.pool.sks-keyservers.net
| gpg: key 2C52609D: "Docker Release Tool (releasedocker) " not changed
| gpg: Total number processed: 1
| gpg: unchanged: 1
| root@VM01:/home/user1#

「docker.list」の確認
| root@VM01:/home/user1# cd /etc/apt/sources.list.d/
| root@VM01:/etc/apt/sources.list.d# ls -l
| total 4
| -rw-r--r-- 1 root root 71 Oct 3 02:14 docker.list
| root@VM01:/etc/apt/sources.list.d#

中身確認
| root@VM01:/etc/apt/sources.list.d# cat docker.list
| deb [arch=amd64] https://apt.dockerproject.org/repo ubuntu-xenial main
| root@VM01:/etc/apt/sources.list.d# docker-compose --version
| The program 'docker-compose' is currently not installed. You can install it by typing:
| apt install docker-compose

Ubuntuのバージョン確認
| root@VM01:/etc/apt/sources.list.d# cat /etc/issue
| Ubuntu 16.04.1 LTS \n \l
|
| root@VM01:/etc/apt/sources.list.d# cat /etc/lsb-release
| DISTRIB_ID=Ubuntu
| DISTRIB_RELEASE=16.04
| DISTRIB_CODENAME=xenial
| DISTRIB_DESCRIPTION="Ubuntu 16.04.1 LTS"
| root@VM01:/etc/apt/sources.list.d#

OSがUbuntu Xenial 16.04 (LTS)の場合はdocker.listを以下に直すが既になってるので無視
| deb https://apt.dockerproject.org/repo ubuntu-xenial main

APTパッケージの更新
| root@VM01:/etc/apt/sources.list.d# sudo apt-get update
| Hit:1 http://security.ubuntu.com/ubuntu xenial-security InRelease
| Get:2 http://download.virtualbox.org/virtualbox/debian xenial InRelease [7,894 B]
| ...

ごみのお掃除
| root@VM01:/etc/apt/sources.list.d# sudo apt-get purge lxc-docker
| Reading package lists... Done
| Building dependency tree
| Reading state information... Done
| Package 'lxc-docker' is not installed, so not removed
| 0 upgraded, 0 newly installed, 0 to remove and 11 not upgraded.
| root@VM01:/etc/apt/sources.list.d#

参照レポジトリの確認
| root@VM01:/etc/apt/sources.list.d# apt-cache policy docker-engine
| docker-engine:
| Installed: 1.12.1-0~xenial
| Candidate: 1.12.1-0~xenial
| Version table:
| *** 1.12.1-0~xenial 500
| 500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
| 100 /var/lib/dpkg/status
| 1.12.0-0~xenial 500
| 500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
| 1.11.2-0~xenial 500
| 500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
| 1.11.1-0~xenial 500
| 500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
| 1.11.0-0~xenial 500
| 500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
| root@VM01:/etc/apt/sources.list.d#

バージョン確認
| root@VM01:/etc/apt/sources.list.d# docker-compose --version
| The program 'docker-compose' is currently not installed. You can install it by typing:
| apt install docker-compose
| root@VM01:/etc/apt/sources.list.d#

もうインストールしたのかと思いきや、まだだったようで。
aptでインストールというので
| root@VM01:/etc/apt/sources.list.d# apt install docker-compose
| Reading package lists... Done
| Building dependency tree
| Reading state information... Done
| The following additional packages will be installed:
| python-backports.ssl-match-hostname python-cffi-backend python-chardet
| ...
| root@VM01:/etc/apt/sources.list.d# docker-compose --version
| docker-compose version 1.5.2, build unknown

めでたしめでたし。多分。


ref.
2016年版、Dockerのすべてが5分でわかるまとめ!(コマンド一覧付き)
http://paiza.hatenablog.com/entry/docker_intro
Ubuntu16.04にDockerをインストール
http://qiita.com/snowman8765/items/d3f2756aeac1f18eccf9
今からでも間に合うDockerの基礎。コンテナとは何か、Dockerfileとは何か。Docker Meetup Tokyo #2
http://www.publickey1.jp/blog/14/dockerdockerfiledocker_meetup_tokyo_2.html


tag : Docker Linux Azure Ubuntu Compose

2016-10-04 14:50 : 開発 : コメント : 0 : トラックバック : 0 :
コメントの投稿
非公開コメント

« next  ホーム  prev »

search

ad



counter


tag cloud

category cloud