駆けだし技術のシマオカズ報告書

Unityのゲーム開発とアプリ開発、セキュリティ,WEB系のことなど

Ubuntu14.04にDockerをインストールしてみた

久しぶりの更新です。ちょっといろいろとかなり忙しかったので全く更新できなかった。

インターン先の会社でDockerを使うことになったので、自分のUbuntu14.04の環境での導入方法をメモ。

 

Dockerって何?って方は以下を参照。

www.atmarkit.co.jp

 

以下の二つを参考にインストール。

qiita.com

tracpath.com

 

 

 

wget -q0- https://get.docker.com/ | sh

 

https://get.docker.comを実際に見ればわかるが、シェルスクリプトが書かれていて、

apt-get update

apt-get install -y -q docker-engine

などが行われている。

 

以下で動作テストしてみる。

 

docker run hello-world

 

 

 

もし以下のようなエラーが出たらdockerが動いていないので、

docker: Cannot connect to the Docker daemon. Is the docker daemon running on this host?.

以下でdockerを動かしてあげる。

 

/etc/init.d/docker restart

 

 

以下のようなのが出れば成功である。

 

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world

4276590986f6: Pull complete
a3ed95caeb02: Pull complete
Digest: sha256:a7d7a8c072a36adb60f5dc932dd5caba8831ab53cbf016bcdd6772b3fbe8c362
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/

root@pt1311-ThinkPad-X230:/etc/default# exit
exit
pt1311@pt1311-ThinkPad-X230:/etc/default$ docker run hello-world

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/

 

 

次にdockerを動かすためにdockerグループに自分のユーザーを追加する。

 

sudo usermod -aG docker [追加したいユーザー名]

 

 

以下のコマンドで、Ubuntuのコンテナを作る。Ubuntu14.04が作られるはず。

docker run -i -t ubuntu /bin/bash

 

 

以下のようにシェルが立ち上がってログインできれば成功。自分の環境ではifconfigやら基本的なコマンドが入っていなかった。

 

root@<コンテナID>:/#

 

 

次回はDockerfileやら書くかもしれません。