LoginSignup
21
16

More than 5 years have passed since last update.

はじめてのDocker

Last updated at Posted at 2015-10-30

はじめに

Dockerをやってみたいと思ったけど、何から始めたら良いのかわからず、
周りに聞いたら下記2点の回答をもらいました。

書籍を読み始めてみましたが、あまりぴんと来なかったので、Docker本家のサイトにシフト。
多分、自分はまず手を動かしたいタイプだからかも。

そんなわけで、Hello Worldを試してみることにしました。
しかし、社内環境ではproxyがあるので、ハマる…。

環境

  • OS: Ubuntu14.04LTS

Hello Worldの手順

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

原因は、proxyだった!

proxyの設定

  • proxyの定義ファイル
    こんなファイルがあることすら知らず…。コメントアウトしているところを適宜変更。

    
    $ sudo vi /etc/default/docker
    
  • docker再起動

    
    $ sudo service docker restart 
    docker stop/waiting
    docker start/running, process 9196
    

Hello World再び

  • 再度実行したけど、変わらず。
    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/
    

21
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
21
16