高速で軽量な仮想環境を構築できるDockerは、
UbuntuにおけるDocker
2017年7月追記:Dockerのリリースポリシーの変更にあわせて、
Dockerはカーネルのコンテナ技術などを利用して、Dockerfile」Dockefileさえあれば、
さてそのDockerを使うためには、
- Docker公式のdocker-ce
(旧称:docker-engine) パッケージをインストールする方法 - Ubuntu公式リポジトリにあるdocker.
ioパッケージをインストールする方法 - snapを使ってdockerパッケージをインストールする方法
最新版を使いたいのであれば、
最新版にこだわりがないのであれば、aptコマンドを実行するだけです。Dockerは昨今のシステムでは必須とも言えるコンポーネントになっているため、
ちなみにdocker.
snap版は、
Dokcer公式のdocker-engineパッケージ
Docker公式のdocker-engineパッケージについては、
必要なパッケージのインストール
まず最初に、
$ sudo apt update
$ sudo apt install curl apt-transport-https ca-certificates \
software-properties-common linux-image-generic linux-image-extra-$(uname -r)
curlはこのあとリポジトリのGPG鍵をダウンロードするために使用します。サーバー版だと最初からインストールされていますが、add-apt-repositoryコマンドのためにインストールしています。ただし普通にUbuntuをインストールすれば、
最後の2つのカーネル関連のパッケージは、
DockerのStorage Driverは、
「linux-image-generic」
カーネルモジュールのうち起動時には使わないものは
Dockerで使うaufsのドライバーはlinux-image-extra-$(uname -r)」
上記を踏まえた上で、
リポジトリ鍵とリポジトリリストの導入
次にリポジトリのGPG鍵とリポジトリのリストを登録しましょう。
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
OK
$ apt-key fingerprint 0EBFCD88
pub 4096R/0EBFCD88 2017-02-22
フィンガー・プリント = 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
uid Docker Release (CE deb)
sub 4096R/F273FCD8 2017-02-22
$ sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
$(lsb_release -cs) \
stable"
$ sudo apt update
apt-keyコマンドを使えばリポジトリ鍵を管理できます。ただし普段使うことはあまりありません。ちなみにadd-apt-repositoryコマンドはPPAの追加でよく使われていますが、/etc/に追加するような使い方も可能です。この使い方で注意しなくてはならないのは、/etc/以下に新規にファイルを追加するのではなく、/etc/の末尾に指定した文字列をそのまま追記するということです。別ファイルで管理したい場合は、echoコマンドとteeコマンドを組み合わせる方法を使用しましょう。
$ echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" \
| sudo tee /etc/apt/sources.list.d/docker.list
将来的にDocker自体が不要になり、
$ sudo apt-key del 0EBFCD88
ここ0EBFCD88」apt-key list」
docker-engineパッケージのインストール
リポジトリの準備ができたらパッケージをインストールします。
$ sudo apt install docker-ce
Ubuntu 16.
$ ps -fe | grep docker root 11731 1 1 18:05 ? 00:00:00 /usr/bin/dockerd -H fd:// root 11741 11731 0 18:05 ? 00:00:00 docker-containerd (略) $ systemctl is-enabled docker enabled
Dockerクライアントがデーモンを操作するためには、sudoコマンドを使って管理者権限を取得するか、dockerグループに所属する必要があります。dockerグループに所属しておけば、sudoなしにコンテナの生成や操作ができますので何かと便利です。このdockerグループはdocker-engineインストール時に自動的に作成されていますので、
$ getent group docker docker:x:999: $ sudo usermod -aG docker $USER (ログインし直す) $ docker info (Dockerデーモンの状態が表示される)
これでインストールは完了です。実際にシンプルなhello-worldコンテナを立ち上げてみましょう。
$ docker search hello-world
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
hello-world Hello World! (an example of minimal Docker... 248 [OK]
tutum/hello-world Image to test docker deployments. Has Apac... 31 [OK]
(以下略)
$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
78445dd45222: Pull complete
Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7
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 ID:
https://cloud.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest 48b5124b2768 3 weeks ago 1.84 kB
Ubuntuのdocker.ioパッケージ
Ubuntuのdocker.
$ sudo apt install docker.io $ getent group docker docker:x:136: $ systemctl is-enabled docker enabled
docker-engineパッケージと同様にsystemdの設定ファイルのインストールや自動起動も設定されていますし、dockerグループも作成されます。ちなみにDocker公式のdocker-engineパッケージはgroupaddコマンドでグループを作っているのに対して、addgroupコマンドでグループを作っているため、dockerグループに自分のアカウントを追加しておきましょう。
$ sudo usermod -aG docker $USER (ログインし直す) $ docker info (Dockerデーモンの状態が表示される)
基本的にDocker公式のdocker-engineパッケージとUbuntuのdocker.
プロキシの設定
DockerデーモンはHTTPS経由でDocker HubのAPIなどにアクセスします。そのため環境によってはデーモンそのものにもプロキシの設定が必要です。プロキシを設定する方法はいくつか存在しますが、
systemdの設定ファイルは/etc/」/lib/」/etc」/lib」
systemdには設定ファイルを部分的に変更する仕組みとして/etc/」Unitファイル名.d」.conf」
DockerデーモンのUnit名はdocker.」/lib/)docker.」
$ sudo mkdir -p /etc/systemd/system/docker.service.d $ cat <<EOF | sudo tee /etc/systemd/system/docker.service.d/proxy.conf [Service] Environment="HTTP_PROXY=http://proxy.example.com:8080/" Environment="HTTPS_PROXY=https://proxy.example.com:8080/" Environment="NO_PROXY=localhost,127.0.0.1" EOF
プロキシの設定は環境変数を指定するだけです。またDockerのローカルリポジトリはプロキシを経由せずにアクセスするようNO_の設定も行なっています。
systemdの設定をリロードし、systemctl restart」
$ sudo systemctl daemon-reload $ systemctl show --property=Environment docker Environment=HTTP_PROXY=http://proxy.example.com:8080/ HTTPS_PROXY=https://proxy.example.com:8080/ NO_PROXY=localhost,127.0.0.1 $ sudo systemctl restart docker
ちなみにsystemctl status」
$ systemctl status docker
(中略)
Drop-In: /etc/systemd/system/docker.service.d
└─proxy.conf
(後略)
上記以外の方法として、/etc/から環境変数を渡す設定手順も存在します。ただしDocker公式のdocker-engineパッケージの場合はUpstartもしくはSysV Init環境でのみこの設定ファイルを使用し、/lib/においてEnvironmentFileにこのファイルを指定しているため、
さて次回はようやくNVIDIA Dockerの話……ではなく、