首次使用Docker
首先
我想尝试使用Docker,但不知道从何开始,向周围的人询问后得到了以下两种答案:
– 你可以先从学习Docker的基本概念开始,然后尝试搭建一个简单的容器环境。
– 或者你也可以直接找一个现有的Docker镜像,运行并试验其中的应用程序。
-
- Docker本家のサイトを見る (http://docs.docker.com/linux/started/)
- 書籍を読む(Docker実践入門 by 中井先生)
我开始阅读书籍,但没有太多共鸣,所以转向Docker官网。
也许是因为我更喜欢亲手动手实践的类型。
因此,我决定尝试一下Hello World。然而,由于内部环境存在代理,导致遇到了困难…。
环境
- OS: Ubuntu14.04LTS
你好世界的步骤 (Nǐ de
- http://docs.docker.com/linux/step_one/
安装Docker
インストール
$ wget -qO- https://get.docker.com/ | sh
…
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 tiffany
Remember that you will have to log out and back in for this to take effect!
確認
$ docker -v
Docker version 1.8.3, build f4bf5c7
docker起動 (サイトには記載がなかったけど、起動が必要)
$ sudo service docker start
docker start/running, process 32503
执行Hello World
実行したらエラーに…。
$ docker run hello-world
Post http:///var/run/docker.sock/v1.20/containers/create: dial unix /var/run/docker.sock: permission denied.
*Are you trying to connect to a TLS-enabled daemon without TLS?
*Is your docker daemon up and running?
sudoをつけて実行してみたら
Network timed out while trying to connect to https://index.docker.io/v1/repositories/library/hello-world/images. You may want to check your internet connection or if you are behind a proxy.
我越来越不明白了……
当我尝试搜索时,有人说要安装docker-machine之类的东西…(尽管我试了也不行…)
http://stackoverflow.com/questions/31990757/network-timed-out-while-trying-to-connect-to-https-index-docker-io
原因在于代理服务器!
代理服务器的设置 de
proxyの定義ファイル
こんなファイルがあることすら知らず…。コメントアウトしているところを適宜変更。
$ sudo vi /etc/default/docker
docker再起動
$ sudo service docker restart
docker stop/waiting
docker start/running, process 9196
你好世界,再次见面.
再度実行したけど、変わらず。
dockerグループにログインユーザ(tiffany)が入っていないためsudoが必要。
dockerグループにログインユーザを入れる方法はまた次回。
$ docker run hello-world
Post http:///var/run/docker.sock/v1.20/containers/create: dial unix /var/run/docker.sock: permission denied.
*Are you trying to connect to a TLS-enabled daemon without TLS?
*Is your docker daemon up and running?
sudo を入れると hello-world が動いた!
$ sudo docker run hello-world
Unable to find image ‘hello-world:latest’ locally
latest: Pulling from library/hello-world
b901d36b6f2f: Pull complete
0a6ba66e537a: Pull complete
Digest: sha256:517f03be3f8169d84711c9ffb2b3235a4d27c1eb4ad147f6248c8040adb93113
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:
The Docker client contacted the Docker daemon.
The Docker daemon pulled the “hello-world” image from the Docker Hub.
The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
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/userguide/