プログラミング

Dockerに入門してみた!Macで使ってみる!

こんにちは,学生エンジニアの迫佑樹(@yuki_99_s)です.

Dockerは,仮想化環境を実現するためのツールです

OSとか,アプリケーションを設定したイメージを丸ごと保存することができます.

thinkit.co.jp

Dockerインストール

Docker Toolbox | Docker

こちらからダウンロードできます.

ダウンロードしたら,.pkgの拡張子のファイルをクリックしてインストール開始.

f:id:McG:20160221155411p:plain

インストールが終わるとこんな感じの画面になるので,Docker Quickstart Terminal.appをクリック

f:id:McG:20160221155603p:plain

クリックしたら勝手にターミナルが開いていろいろセットしてくれる.

f:id:McG:20160221155900p:plain

こんな感じのアスキーアートがでてきたら終了.

Hello Worldしてみる

docker run hello-worldとコマンドを打つと,以下の実行結果が返ってくるはず.

% 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/userguide/

CentOSを落としてくる

docker pull centos

とやってあげると,centosのイメージが降ってくる.

こんな感じ.

f:id:McG:20160221162143p:plain

docker imagesコマンドを打つと,イメージの一覧が確認できる…はずだったんだが,Cannot connect to the Docker daemon. Is the docker daemon running on this host? となって怒られた.

docker-machine env defaultといって環境変数を確認してみる.

% docker-machine env default
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/Users/yukisako/.docker/machine/machines/default"
export DOCKER_MACHINE_NAME="default"
# Run this command to configure your shell:
# eval $(docker-machine env default)

なるほど,configureをするために,eval $(docker-machine env default)というコマンドを打つ必要があると.

これを打ってから再びdocker imagesコマンドを打つ.

% docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos              latest              0f0be3675ebb        3 days ago          196.6 MB
hello-world         latest              690ed74de00f        4 months ago        960 B

無事に入っていることがわかります.

docker inspect リポジトリ: タグ名 もしくは docker inspect ID で詳細確認.

docker rmi リポジトリ: タグ名 もしくは docker rmi ID でイメージの削除ができる.

公式LINEに登録してビジネスを学ぼう
無料LINEマガジンへの登録で、5つの豪華特典をプレゼント!
  1. 日本一わかりやすい「経済的自立を果たす人生攻略の10ステップ」(33分23秒)
  2. 見るだけで売上3倍は確実。「時給10円から年商10億」に至るまでの全ての道のり(39分15秒)
  3. 有料講演会の内容を公開。最短最速で0→1を立ち上げる起業術(1時間08分35秒)
  4. 起業初心者へ向けた即金で10万円を稼ぐ具体マニュアル(PDF24ページ)
  5. 資本主義社会においてお金持ちになる5つのルール(17分36秒)
その他、有益なコラムを完全無料で閲覧し放題!
\豪華特典を今すぐゲット/