Dockerとは
// 割愛 あとで書く
参考にした記事
- Docker を Mac で使ってみた(Nodeアプリ例) ::ハブろぐ
- MacにVirtualBoxをインストールする方法 | Windows on Mac BootCampを使って MacでWindowsを動かそう
- How do you list containers in Docker.io? - Stack Overflow
- Command line - Docker Documentation
- boot2dockerでDockerを使おうとしたら「malformed HTTP response」エラーが発生してしまった場合の対処 - Qiita
おおまかな流れ
- VirtualBoxをインストール
- boot2dockerコマンドをインストール
- LinuxVMを立ち上げる
- Dockerコンテナを作ってその中で任意のコマンドを実行してみる
- Dockerfileを使ってDockerコンテナを作ってみる
VirtualBoxをインストール
Downloads – Oracle VM VirtualBox ここに行く。
Macなのでこれかな
dmgファイル落ちてきたら実行してインストーラ起動するのでいつも通り進めていく、とアプリケーションに「VirtualBox」ができる。
起動してみる
boot2dockerコマンドをインストールする
なぜboot2dockerが必要かというと(以下略
% cd % brew search boot2docker boot2docker % brew install boot2docker # 中略 (beer) /usr/local/Cellar/boot2docker/1.2.0: 2 files, 7.2M % which boot2docker /usr/local/bin/boot2docker % which docker /usr/local/bin/docker %
(より道)dockerコマンドについて
ちょっとより道します。以下のコマンドを打ってdockerについていろいろ知りたい
% docker help % docker help search % docker help pull % docker help ps
Linux VMを立ち上げる
boot2dockerコマンドを使って、VirtualBox上にLinuxVMをひとつ立ち上げます。 これそのものはDockerコンテナとは別概念で、単なるVirtualBox上のVMです。上記(以下略とした内容)を参考。
% boot2docker init
ssh keyなどが作られた
% boot2docker up
この段階で、VirtualBox上にDockerが動くためのLinuxVMがひとつ立ち上がってる状態になった
boot2docker up
したとき、以下のメッセージが出ていたので
To connect the Docker client to the Docker daemon, please set: export DOCKER_HOST=tcp://192.168.59.103:2376 export DOCKER_CERT_PATH=/Users/otiai10/.docker/boot2docker-vm
必要があれば.zshrcなどに書いておく。
Dockerコンテナを作ってその中で任意のコマンドを実行してみる
% docker --tls run ubuntu echo "Hello, Docker!!" Unable to find image 'ubuntu' locally ubuntu:latest: The image you are pulling has been verified 511136ea3c5a: Pull complete 97fd97495e49: Pull complete 2dcbbf65536c: Pull complete 6a459d727ebb: Pull complete 8f321fc43180: Pull complete 03db2b23cf03: Pull complete 9cbaf023786c: Pull complete Status: Downloaded newer image for ubuntu:latest Hello, Docker!!
imageができてることがわかる
% docker --tls images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE ubuntu latest 9cbaf023786c 8 days ago 192.8 MB %
Dockerfileを使ってDockerコンテナを作ってみる
~/hoge/Dockerfile
FROM ubuntu MAINTAINER otiai10 RUN echo "やるったらやる (๑˃̵ᴗ˂̵)و"
% cd ~/hoge % docker --tls build -t hoge ./ Sending build context to Docker daemon 2.56 kB Sending build context to Docker daemon Step 0 : FROM ubuntu ---> 9cbaf023786c Step 1 : MAINTAINER otiai10 ---> Using cache ---> df792ded8b5f Step 2 : RUN echo "やるったらやる (๑˃̵ᴗ˂̵)و" ---> Running in 1be4cd57674d やるったらやる (๑˃̵ᴗ˂̵)و ---> 44b481cfe206 Removing intermediate container 1be4cd57674d Successfully built 44b481cfe206 %
次回
Dockerコンテナ上でなんらかのサーバアプリケーションを作ってブラウザからアクセスしてみる
DRYな備忘録