###Dockerとは
アプリケーションを実際に動かす際に、本番環境とローカル環境では大きく動作が異なる場合がある。
環境設定の差で本番環境で動かなくなるケースも多々ある。
なので開発するさいにはなるべく本番環境に近い状態で行うのが好ましい。
その本番環境に近い状態でアプリケーションを実行するためにDockerを使用する。
Dockerは起動スピードに優れている他、AWSやGoogle Cloud Platformなどのクラウドサービスでコンテナを実行できるという利点がある。
###Dockerのインストール
まずはDockerのホームページを開く
次に上部タブのProductsをクリック
現在はそのProducts画面の最下部にあるGet Startedをクリックするとインストールページに遷移します。
そちらに各種ダウンロードボタンがあるので、Macの人はMac用のダウンロードボタンから取得する
またターミナルで以下のコマンドを打つとDockerのバージョン表示がでるので、これが表示されてれば問題ない。
$ docker version
Client: Docker Engine - Community
Version: 19.03.8
API version: 1.40
Go version: go1.12.17
Git commit: afacb8b
Built: Wed Mar 11 01:21:11 2020
OS/Arch: darwin/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.8
API version: 1.40 (minimum version 1.12)
Go version: go1.12.17
Git commit: afacb8b
Built: Wed Mar 11 01:29:16 2020
OS/Arch: linux/amd64
Experimental: false
Dockerを起動してみる
$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:6a65f928fb91fcfbc963f7aa6d57c8eeb426ad9a20c7ee045538ef34847f44f1
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://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
上記でHello from Docker!と表示されている。
これでDockerが起動していることがわかる。