docker、名前は聞いたことあるものの、全然ノータッチだったので、勉強してみた。
いつも「dockerとvagrantの違い」あたりを読んで挫折し始めるので、そこらへんはスキップします。
dockerやインフラ初心者にとっては、そこってホントどうでもいいところなんですよね・・・(少なくとも初心者である時点では)
ということで、手を動かすことメインで入門してみました。
参考サイト
環境
windows10Pro (10Sからの変更)
dockerインストール
適当にインストーラ落として入れればok
docker ps
さっそくエラーが出る
PS C:\Users\dormi> docker ps error during connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.37/containers/json: open //./pipe/docker_engine: The system cannot find the file specified. In the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running.
dockerが立ち上がってない? Win+Qでアプリ検索してdocker立ち上げ。
PS C:\Users\dormi> docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
無事にでたー!
docker run hello-world
PS C:\Users\dormi> docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world ca4f61b1923c: Pull complete Digest: sha256:97ce6fa4b6cdc0790cda65fe7290b74cfebd9fa0c9b8c38e979330d547d22ce1 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. (amd64) 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 ID: https://cloud.docker.com/ For more examples and ideas, visit: https://docs.docker.com/engine/userguide/
まずlocalのイメージを探して、なければダウンロードするんですね。 というか、番号付きリストのところに何が起こったか書いてありますね。やさしい。
docker pull
PS C:\Users\dormi> docker pull alpine Using default tag: latest latest: Pulling from library/alpine ff3a5c916c92: Pull complete Digest: sha256:7b848083f93822dd21b0a2f14a110bd99f6efb4b838d499df6d04a49d0debf8b Status: Downloaded newer image for alpine:latest
run
はダウンロードして実行するけど、 pull
は落とすだけって感じ?
docker images
PS C:\Users\dormi> docker images REPOSITORY TAG IMAGE ID CREATED SIZE alpine latest 3fd9065eaf02 2 months ago 4.15MB hello-world latest f2a91732366c 3 months ago 1.85kB
ダウンロードしたイメージが見れるっぽい。
docker run
PS C:\Users\dormi> docker run alpine echo "hello from alpine" hello from alpine
コマンドやってることは分かったけど、補完依存症の僕にとっては、イメージ名は補完してほしいな感。
fishとか使ったらいい感じに補完してくれたりしないのかな。
docker run -it
PS C:\Users\dormi> docker run -it alpine bin/sh / # ls bin dev etc home lib media mnt proc root run sbin srv sys tmp usr var
なるほど。 -it
でイメージに入れるんですね。
-i
と -t
が何を指してるかは、これからわかるのかな?
(なんとなく想像はつくけど。)
docker ps(2回目)
PS C:\Users\dormi> docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 209aff4c011b alpine "bin/sh" 5 minutes ago Up 5 minutes agitated_sinoussi
起動中のイメージが表示されるのね
docker stop
PS C:\Users\dormi> docker stop 209aff4c011b 209aff4c011b
イメージを停止させるのかな?
ちょっと時間かかる
docker start
PS C:\Users\dormi> docker start 209aff4c011b 209aff4c011b
なるほど。 stop
したイメージを再開させるのか。
docker attach
PS C:\Users\dormi> docker attach 209aff4c011b / #
これで stop
したイメージにまた入れるのね。
docker rm
PS C:\Users\dormi> docker rm 209aff4c011b Error response from daemon: You cannot remove a running container 209aff4c011b8f7ba6f469ef17540c599125ccad6aff6cfb1a9b2d907792ed7a. Stop the container before attempting removal or force remove
stop
しないまま実行しようとすると怒られる
PS C:\Users\dormi> docker stop 209aff4c011b 209aff4c011b PS C:\Users\dormi> docker rm 209aff4c011b 209aff4c011b
いけた。
PS C:\Users\dormi> docker start 209aff4c011b Error response from daemon: No such container: 209aff4c011b Error: failed to start containers: 209aff4c011b
消すともう再開できないらしい。
サーバーを動かす
PS C:\Users\dormi> docker run --name static-site -e AUTHOR="Docker" -d -p 80:80 seqvence/static-site Unable to find image 'seqvence/static-site:latest' locally latest: Pulling from seqvence/static-site fdd5d7827f33: Pull complete a3ed95caeb02: Pull complete 716f7a5f3082: Pull complete 7b10f03a0309: Pull complete aff3ab7e9c39: Pull complete Digest: sha256:41b286105f913fb7a5fbdce28d48bc80f1c77e3c4ce1b8280f28129ae0e94e9e Status: Downloaded newer image for seqvence/static-site:latest ff91ee73c66b3b175f148a7d0e2c0bda8f24f9c9a26467df1d2a6c6d4d9034ec
引数多くて「ウっ」てなる。
--name
は別にいらんのかなーとも思う。
サイトを表示するためにはデフォルトでバインドされるIPアドレスを調べないといけないらしいが・・・
PS C:\Users\dormi> docker-machine ip default Docker machine "default" does not exist. Use "docker-machine ls" to list machines. Use "docker-machine create" to add a new one.
なんかエラー出る・・・
とりあえず http://localhost
でつながったけど・・・・微妙ですね。
ここの設定をどうやって出せるかは知りたいところ。
ネット徘徊してたらこれでIPアドレスわかるらしいが・・・
PS C:\Users\dormi> docker inspect -f "{{ .NetworkSettings.IPAddress }}" ff91ee73c66b 172.17.0.2
なんか違いそう。 これ内部のIPアドレスよね。
色々調べた結果、Dockerへの接続を知りたいだけなので、
PS C:\Users\dormi> ipconfig
で良かったのだった・・・