DockerでKeras
Docker上でKerasを動かそうとDockerfileを書いていた。 以下のようなシンプルなもの。
FROM nvidia/cuda:8.0-cudnn5-runtime ENV [プロキシ設定] RUN APT-get update RUN apt-get -y install python3pip curl RN pip3 install keras tensorflow-gpu
が、これではkerasのサンプル(mnist_mlp.pyなど)が動かず。エラーを見るとtensorflowをインポートできてない様子。パスが通ってないのかな。。。
その後、KerasのgithubにDockerfileを発見。makeしたところとりあえず動作。keras用のユーザがあり、そこへログインしていたが、rootユーザのパスワードが分からずエディタ他を入れられない。。。rootのパスワード設定はDockerだとどうなるのだろう。Dockerfileにはそれらしき記述はなし。
参考:
Dockerfileに手を入れた場所は、環境に合わせたproxy設定回りのみ。
Docker 起動中のコンテナに複数のコンソールで入る。
コンソールが2枚ほしくなり、何も考えず起動中のコンテナにattachすると、1つのプロセスに2つのコンソールとなってしまった。少し調べると、以下の様にプロセスを注入してやれば良いことが分かった。
docker exec -it [Container name] /bin/bash
参考
Docker, buildしたイメージをインタラクティブモードで起動する
docker run -i -t [yourimage] /bin/bash
等とする。
Docker build時のProxy越え
症状:
Docker イメージ内でapt-get等が失敗する
解決策: Dockerfileにproxyの環境変数を設定する
Dockerのバージョンが1.9からは環境変数が渡せるとのことだが、使用しているバージョンがそれ未満である場合や、Dockerfileに環境変数を設定することに懸念が無いのであればDockerfileにProxy設定を書いてしまった方が楽だと思う。Dockerfileには以下のような文を加える。認証が必要な場合にはユーザー名とパスワードを書く。
ENV http_proxy http://[proxy_user]:[proxy_password]@[proxy_address]:[port]/ ENV https_proxy htttps://[proxy_user]:[proxy_password]@[proxy_address]:[port]/
参照
Docker, Get started Learn by exampleやってみた
うん、面白い。習うより慣れろでちょっと触ってみた。Learn by example. Network containers.
参考:Network containers | Docker Documentation
Hello! Docker
$ sudo docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world b04784fba78d: Pull complete Digest: sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74f 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/
Dcoker上で、bashを起動してみる。かな?
$ sudo docker run -it ubuntu bash Unable to find image 'ubuntu:latest' locally latest: Pulling from library/ubuntu bd97b43c27e3: Pull complete 6960dc1aba18: Pull complete 2b61829b0db5: Pull complete 1f88dc826b14: Pull complete 73b3859b1e43: Pull complete Digest: sha256:ea1d854d38be82f54d39efe2c67000bed1b03348bcc2f3dc094f260855dff368 Status: Downloaded newer image for ubuntu:latest
ネットワークでmy_bridgeを作る
$ sudo docker network create -d bridge my_bridge 192d0ca4764442d62f634dfda5afdf58d8412ed4743da2c80f1b36a907864c02
my_bridgeをチェック
$ docker network inspect my_bridge [ { "Name": "my_bridge", "Id": "192d0ca4764442d62f634dfda5afdf58d8412ed4743da2c80f1b36a907864c02", "Created": "2017-06-19T15:41:11.497066293+09:00", "Scope": "local", "Driver": "bridge", "EnableIPv6": false, "IPAM": { "Driver": "default", "Options": {}, "Config": [ { "Subnet": "172.18.0.0/16", "Gateway": "172.18.0.1" } ] }, "Internal": false, "Attachable": false, "Containers": {}, "Options": {}, "Labels": {} } ]
最初からあるbridgeを覗いてみる
$ docker network inspect bridge [ { "Name": "bridge", "Id": "87df18fc20cd4f07134043df4e6128c8976c805fd9e0975df7a8ed7a5e943062", "Created": "2017-06-19T14:55:57.194021424+09:00", "Scope": "local", "Driver": "bridge", "EnableIPv6": false, "IPAM": { "Driver": "default", "Options": null, "Config": [ { "Subnet": "172.17.0.0/16", "Gateway": "172.17.0.1" } ] }, "Internal": false, "Attachable": false, "Containers": {}, "Options": { "com.docker.network.bridge.default_bridge": "true", "com.docker.network.bridge.enable_icc": "true", "com.docker.network.bridge.enable_ip_masquerade": "true", "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0", "com.docker.network.bridge.name": "docker0", "com.docker.network.driver.mtu": "1500" }, "Labels": {} } ]
db
$ docker inspect --format='{{json .NetworkSettings.Networks}}' db {"my_bridge":{"IPAMConfig":null,"Links":null,"Aliases":["6cd19d6243fd"],"NetworkID":"192d0ca4764442d62f634dfda5afdf58d8412ed4743da2c80f1b36a907864c02","EndpointID":"12d728caa2060e6239dd237cb0708ecd6464fdfc0d4f84de8292778c963d09af","Gateway":"172.18.0.1","IPAddress":"172.18.0.2","IPPrefixLen":16,"IPv6Gateway":"","GlobalIPv6Address":"","GlobalIPv6PrefixLen":0,"MacAddress":"02:42:ac:12:00:02"}}
app.pyを走らせる
$ sudo docker run -d --name web training/webapp python app.py Unable to find image 'training/webapp:latest' locally latest: Pulling from training/webapp e190868d63f8: Pull complete 909cd34c6fd7: Pull complete 0b9bfabab7c1: Pull complete a3ed95caeb02: Pull complete 10bbbc0fc0ff: Pull complete fca59b508e9f: Pull complete e7ae2541b15b: Pull complete 9dd97ef58ce9: Pull complete a4c1b0cb7af7: Pull complete Digest: sha256:06e9c1983bd6d5db5fba376ccd63bfa529e8d02f23d5079b8f74a616308fb11d Status: Downloaded newer image for training/webapp:latest c2acecacb7b73a123f1b84d62138c73b7e5d24866b51de5b0fc39efe8c844f78
webをinspect
$ docker inspect --format='{{json .NetworkSettings.Networks}}' web {"bridge":{"IPAMConfig":null,"Links":null,"Aliases":null,"NetworkID":"87df18fc20cd4f07134043df4e6128c8976c805fd9e0975df7a8ed7a5e943062","EndpointID":"cbc41fe982497845ac8c19c5b31e01610d5f408b18ce9f40bf4c1e17c5948c14","Gateway":"172.17.0.1","IPAddress":"172.17.0.2","IPPrefixLen":16,"IPv6Gateway":"","GlobalIPv6Address":"","GlobalIPv6PrefixLen":0,"MacAddress":"02:42:ac:11:00:02"}}
フォーマットを端折ってみた
$ docker inspect web [ { "Id": "c2acecacb7b73a123f1b84d62138c73b7e5d24866b51de5b0fc39efe8c844f78", "Created": "2017-06-19T08:29:52.027401227Z", "Path": "python", "Args": [ "app.py" ], "State": { "Status": "running", "Running": true, "Paused": false, "Restarting": false, "OOMKilled": false, "Dead": false, "Pid": 7947, "ExitCode": 0, "Error": "", "StartedAt": "2017-06-19T08:29:53.087901528Z", "FinishedAt": "0001-01-01T00:00:00Z" }, "Image": "sha256:6fae60ef344644649a39240b94d73b8ba9c67f898ede85cf8e947a887b3e6557", "ResolvConfPath": "/var/lib/docker/containers/c2acecacb7b73a123f1b84d62138c73b7e5d24866b51de5b0fc39efe8c844f78/resolv.conf", "HostnamePath": "/var/lib/docker/containers/c2acecacb7b73a123f1b84d62138c73b7e5d24866b51de5b0fc39efe8c844f78/hostname", "HostsPath": "/var/lib/docker/containers/c2acecacb7b73a123f1b84d62138c73b7e5d24866b51de5b0fc39efe8c844f78/hosts", "LogPath": "/var/lib/docker/containers/c2acecacb7b73a123f1b84d62138c73b7e5d24866b51de5b0fc39efe8c844f78/c2acecacb7b73a123f1b84d62138c73b7e5d24866b51de5b0fc39efe8c844f78-json.log", "Name": "/web", "RestartCount": 0, "Driver": "aufs", "MountLabel": "", "ProcessLabel": "", "AppArmorProfile": "", "ExecIDs": null, "HostConfig": { "Binds": null, "ContainerIDFile": "", "LogConfig": { "Type": "json-file", "Config": {} }, "NetworkMode": "default", "PortBindings": {}, "RestartPolicy": { "Name": "no", "MaximumRetryCount": 0 }, "AutoRemove": false, "VolumeDriver": "", "VolumesFrom": null, "CapAdd": null, "CapDrop": null, "Dns": [], "DnsOptions": [], "DnsSearch": [], "ExtraHosts": null, "GroupAdd": null, "IpcMode": "", "Cgroup": "", "Links": null, "OomScoreAdj": 0, "PidMode": "", "Privileged": false, "PublishAllPorts": false, "ReadonlyRootfs": false, "SecurityOpt": null, "UTSMode": "", "UsernsMode": "", "ShmSize": 67108864, "Runtime": "runc", "ConsoleSize": [ 0, 0 ], "Isolation": "", "CpuShares": 0, "Memory": 0, "NanoCpus": 0, "CgroupParent": "", "BlkioWeight": 0, "BlkioWeightDevice": null, "BlkioDeviceReadBps": null, "BlkioDeviceWriteBps": null, "BlkioDeviceReadIOps": null, "BlkioDeviceWriteIOps": null, "CpuPeriod": 0, "CpuQuota": 0, "CpuRealtimePeriod": 0, "CpuRealtimeRuntime": 0, "CpusetCpus": "", "CpusetMems": "", "Devices": [], "DiskQuota": 0, "KernelMemory": 0, "MemoryReservation": 0, "MemorySwap": 0, "MemorySwappiness": -1, "OomKillDisable": false, "PidsLimit": 0, "Ulimits": null, "CpuCount": 0, "CpuPercent": 0, "IOMaximumIOps": 0, "IOMaximumBandwidth": 0 }, "GraphDriver": { "Name": "aufs", "Data": null }, "Mounts": [], "Config": { "Hostname": "c2acecacb7b7", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "ExposedPorts": { "5000/tcp": {} }, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ], "Cmd": [ "python", "app.py" ], "Image": "training/webapp", "Volumes": null, "WorkingDir": "/opt/webapp", "Entrypoint": null, "OnBuild": null, "Labels": {} }, "NetworkSettings": { "Bridge": "", "SandboxID": "744f84e01741f3a5e8c687e272b9a7859dd7f000422c72da7c3ba79696b4be52", "HairpinMode": false, "LinkLocalIPv6Address": "", "LinkLocalIPv6PrefixLen": 0, "Ports": { "5000/tcp": null }, "SandboxKey": "/var/run/docker/netns/744f84e01741", "SecondaryIPAddresses": null, "SecondaryIPv6Addresses": null, "EndpointID": "cbc41fe982497845ac8c19c5b31e01610d5f408b18ce9f40bf4c1e17c5948c14", "Gateway": "172.17.0.1", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "IPAddress": "172.17.0.2", "IPPrefixLen": 16, "IPv6Gateway": "", "MacAddress": "02:42:ac:11:00:02", "Networks": { "bridge": { "IPAMConfig": null, "Links": null, "Aliases": null, "NetworkID": "87df18fc20cd4f07134043df4e6128c8976c805fd9e0975df7a8ed7a5e943062", "EndpointID": "cbc41fe982497845ac8c19c5b31e01610d5f408b18ce9f40bf4c1e17c5948c14", "Gateway": "172.17.0.1", "IPAddress": "172.17.0.2", "IPPrefixLen": 16, "IPv6Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "MacAddress": "02:42:ac:11:00:02" } } } } ]
IPアドレスを表示
$ docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' web 172.17.0.2
pingがロスしているのを確認
$ docker exec -it db bash root@6cd19d6243fd:/# ping 172.17.0.2 PING 172.17.0.2 (172.17.0.2) 56(84) bytes of data. ^C --- 172.17.0.2 ping statistics --- 12 packets transmitted, 0 received, 100% packet loss, time 11087ms
ネットワークを見てみた
root@6cd19d6243fd:/# ifconfig eth0 Link encap:Ethernet HWaddr 02:42:ac:12:00:02 inet addr:172.18.0.2 Bcast:0.0.0.0 Mask:255.255.0.0 inet6 addr: fe80::42:acff:fe12:2/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1455 errors:0 dropped:0 overruns:0 frame:0 TX packets:21 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:172944 (172.9 KB) TX bytes:1866 (1.8 KB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:275 errors:0 dropped:0 overruns:0 frame:0 TX packets:275 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1 RX bytes:24545 (24.5 KB) TX bytes:24545 (24.5 KB)
$ docker exec -it db bash root@6cd19d6243fd:/# root@6cd19d6243fd:/# ping web PING web (172.18.0.3) 56(84) bytes of data. 64 bytes from web.my_bridge (172.18.0.3): icmp_seq=1 ttl=64 time=0.099 ms 64 bytes from web.my_bridge (172.18.0.3): icmp_seq=2 ttl=64 time=0.079 ms 64 bytes from web.my_bridge (172.18.0.3): icmp_seq=3 ttl=64 time=0.079 ms ^C --- web ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 1999ms rtt min/avg/max/mdev = 0.079/0.085/0.099/0.014 ms root@6cd19d6243fd:/# root@6cd19d6243fd:/# ifconfig eth0 Link encap:Ethernet HWaddr 02:42:ac:12:00:02 inet addr:172.18.0.2 Bcast:0.0.0.0 Mask:255.255.0.0 inet6 addr: fe80::42:acff:fe12:2/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1495 errors:0 dropped:0 overruns:0 frame:0 TX packets:26 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:177126 (177.1 KB) TX bytes:2244 (2.2 KB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:283 errors:0 dropped:0 overruns:0 frame:0 TX packets:283 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1 RX bytes:25226 (25.2 KB) TX bytes:25226 (25.2 KB) root@6cd19d6243fd:/# ping 172.17.0.2 PING 172.17.0.2 (172.17.0.2) 56(84) bytes of data. ^C --- 172.17.0.2 ping statistics --- 4 packets transmitted, 0 received, 100% packet loss, time 3022ms root@6cd19d6243fd:/#
my_bridgeとwebをコネクトする。一瞬。
$ docker network connect my_bridge web
pingすると通る。素晴らしい。
$ docker exec -it db bash root@6cd19d6243fd:/# root@6cd19d6243fd:/# ping web PING web (172.18.0.3) 56(84) bytes of data. 64 bytes from web.my_bridge (172.18.0.3): icmp_seq=1 ttl=64 time=0.099 ms 64 bytes from web.my_bridge (172.18.0.3): icmp_seq=2 ttl=64 time=0.079 ms 64 bytes from web.my_bridge (172.18.0.3): icmp_seq=3 ttl=64 time=0.079 ms ^C --- web ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 1999ms rtt min/avg/max/mdev = 0.079/0.085/0.099/0.014 ms
Ubuntu 16.04(xenial) lts へのDockerインストールとProxy設定
公式のドキュメントが充実しているので、基本的にはそれを参照すれば良い。
以下は個人的な備忘録。
インストール手順
- Dockerのアカウントを作る
Docker - Build, Ship, and Run Any App, Anywhere
- 公式ドキュメント(英語)を参照してインストール。
Get Docker for Ubuntu | Docker Documentation
- Dockerのリポジトリに接続できなかったので、パッケージから。(“/pool"の下にある)
Index of /linux/ubuntu/dists/xenial/pool/stable/
Proxy設定
Ubuntu 16.04 lts はsystem.d(まだあまり理解していない)ので、以前のproxy設定方法ではDockerは読み込んでくれないらしい。 Proxy設定についても公式ドキュメントを参照すれば問題ない。Admin guide下の記載通りにやればOK。 認証が必要なProxy環境下では、以下のようにすれば大丈夫。(Proxyのパスワードが見られると困る場合は要工夫)
Environment="HTTP_PROXY=htttp://<USERNAME>:<PASSWORD>@<PROXYADDRESS>:<PORT>/"
参照:Control and configure Docker with systemd | Docker Documentation
Dockerのリポジトリへ接続できなかった件について。
少し調査したのでメモ。apt-get updateすると以下のようなエラーが出る。
無視:6 https://download.docker.com/linux/ubuntu xenial/stable Translation-ja 無視:7 https://download.docker.com/linux/ubuntu xenial/stable Translation-en 無視:8 https://download.docker.com/linux/ubuntu xenial/stable amd64 DEP-11 Metadata 無視:9 https://download.docker.com/linux/ubuntu xenial/stable DEP-11 64x64 Icons ヒット:12 http://archive.ubuntu.com/ubuntu xenial-backports InRelease ヒット:13 http://archive.ubuntu.com/ubuntu xenial-security InRelease パッケージリストを読み込んでいます... 完了 W: リポジトリ https://download.docker.com/linux/ubuntu xenial Release には Release ファイルがありません。 N: このようなリポジトリから取得したデータは認証できないので、データの使用は潜在的に危険です。 N: リポジトリの作成とユーザ設定の詳細は、apt-secure(8) man ページを参照してください。 E: https://download.docker.com/linux/ubuntu/dists/xenial/stable/binary-amd64/Packages の取得に失敗しました Received HTTP code 407 from proxy after CONNECT E: いくつかのインデックスファイルのダウンロードに失敗しました。これらは無視されるか、古いものが代わりに使われます。
エラーメッセージでググると、過去のリポジトリが悪さしているという記載があったので、それに習って削除してみたが、この環境では効果なし。 14.04ltsからバージョンアップした環境なのでビンゴかと思ったんだけどなぁ。。。
DELL XPS15(9560)購入と、バッテリー充電閾値設定
4Kモデルではなく、FHDモデルを購入。15インチ液晶&NVIDIA GPU搭載がポイント。
バッテリー容量は4Kモデルより少ない。フル充電でバッテリーライフは3時間ほど。節電モードをONにすれば8時間ほどになりそう(表示上)。 ACアダプタもしくはUSB type cのモバイルバッテリーを持ち歩く必要があるかもしれないが、4Kモデルのレビュー記事でもバッテリーの持ちは良くなさそうであったし。 ACアダプタは想定よりスリム(一昔前のDellを覚悟していたからであって、決して小さくはない)。 FHDモデルは4Kモデルより200g程度軽いので、常にACアダプタを持ち歩く覚悟の上でこちらを選択。 液晶はグレア液晶かと思っていたが、FHDモデルはノングレアだった。個人的にはノングレアのほうが嬉しいので問題なし。4Kモデルはタッチパネル搭載だからグレア液晶か。
Lenovoではおなじみのバッテリー充電を制限するものがDellでも提供されていないかと検索すると、 ビジネスモデルではプリンストールされているDell command/Power managementが配布されており、これをインストールすると有効にできるとのこと。 もっとも新しいバージョンを選択し、インストールするだけで有効になった。 これでACアダプタをさしっぱなしにした運用であっても、バッテリー劣化を軽減できるはず。
参考: デルの電源管理ソフトウェア、Dell Command | Power Management が結構イケてる件 - テックセンター - Blog - テックセンター - Dell コミュニティ