Docker を Mac に Homebrew を使ってインストールするコマンドまとめ
# インストール brew cask install docker # ↓不要 #brew install docker-compose # 起動(メニューバーの Docker アイコンが落ち着いたら次の工程へ) open /Applications/Docker.app/ # インストール確認 docker --version docker-compose --version # 動作確認 docker run hello-world cat <<EOF > docker-compose.yml version: '3' services: hello: image: hello-world EOF docker-compose up docker-compose down
実際に作業した記録
$ # インストール $ brew cask install docker ==> Satisfying dependencies ==> Downloading https://download.docker.com/mac/stable/26399/Docker.dmg ######################################################################## 100.0% ==> Verifying checksum for Cask docker ==> Installing Cask docker ==> Moving App 'Docker.app' to '/Applications/Docker.app'. ? docker was successfully installed! $ $ $ $ brew install docker-compose ==> Installing dependencies for docker-compose: docker ==> Installing docker-compose dependency: docker ==> Downloading https://homebrew.bintray.com/bottles/docker-18.06.0.sierra.bottle.tar.gz Already downloaded: /Users/oki2a24/Library/Caches/Homebrew/docker-18.06.0.sierra.bottle.tar.gz ==> Pouring docker-18.06.0.sierra.bottle.tar.gz Error: The `brew link` step did not complete successfully The formula built, but is not symlinked into /usr/local Could not symlink bin/docker Target /usr/local/bin/docker already exists. You may want to remove it: rm '/usr/local/bin/docker' To force the link and overwrite all conflicting files: brew link --overwrite docker To list all files that would be deleted: brew link --overwrite --dry-run docker Possible conflicting files are: /usr/local/bin/docker -> /Applications/Docker.app/Contents/Resources/bin/docker ==> Caveats Bash completion has been installed to: /usr/local/etc/bash_completion.d zsh completions have been installed to: /usr/local/share/zsh/site-functions ==> Summary ? /usr/local/Cellar/docker/18.06.0: 8 files, 52.3MB ==> Installing docker-compose ==> Downloading https://homebrew.bintray.com/bottles/docker-compose-1.22.0.sierra.bottle.tar.gz Already downloaded: /Users/oki2a24/Library/Caches/Homebrew/docker-compose-1.22.0.sierra.bottle.tar.gz ==> Pouring docker-compose-1.22.0.sierra.bottle.tar.gz Error: The `brew link` step did not complete successfully The formula built, but is not symlinked into /usr/local Could not symlink bin/docker-compose Target /usr/local/bin/docker-compose already exists. You may want to remove it: rm '/usr/local/bin/docker-compose' To force the link and overwrite all conflicting files: brew link --overwrite docker-compose To list all files that would be deleted: brew link --overwrite --dry-run docker-compose Possible conflicting files are: /usr/local/bin/docker-compose -> /Applications/Docker.app/Contents/Resources/bin/docker-compose ==> Caveats Bash completion has been installed to: /usr/local/etc/bash_completion.d zsh completions have been installed to: /usr/local/share/zsh/site-functions ==> Summary ? /usr/local/Cellar/docker-compose/1.22.0: 886 files, 9.4MB ==> Caveats ==> docker Bash completion has been installed to: /usr/local/etc/bash_completion.d zsh completions have been installed to: /usr/local/share/zsh/site-functions ==> docker-compose Bash completion has been installed to: /usr/local/etc/bash_completion.d zsh completions have been installed to: /usr/local/share/zsh/site-functions $ $ $ $ # 起動(メニューバーの Docker アイコンが落ち着いたら次の工程へ) $ open /Applications/Docker.app/ $ $ $ $ # インストール確認 $ docker --version Docker version 18.06.0-ce, build 0ffa825 $ docker-compose --version docker-compose version 1.22.0, build f46880f $ $ $ $ # 動作確認 $ docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 9db2ca6ccae0: Pull complete Digest: sha256:4b8ff392a12ed9ea17784bd3c9a8b1fa3299cac44aca35a85c90c5e3c7afacdc 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/engine/userguide/ $ $ $ $ cat <<EOF > docker-compose.yml > version: '3' > services: > hello: > image: hello-world > EOF $ docker-compose up Creating network "oki2a24_default" with the default driver Creating oki2a24_hello_1 ... done Attaching to oki2a24_hello_1 hello_1 | hello_1 | Hello from Docker! hello_1 | This message shows that your installation appears to be working correctly. hello_1 | hello_1 | To generate this message, Docker took the following steps: hello_1 | 1. The Docker client contacted the Docker daemon. hello_1 | 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. hello_1 | (amd64) hello_1 | 3. The Docker daemon created a new container from that image which runs the hello_1 | executable that produces the output you are currently reading. hello_1 | 4. The Docker daemon streamed that output to the Docker client, which sent it hello_1 | to your terminal. hello_1 | hello_1 | To try something more ambitious, you can run an Ubuntu container with: hello_1 | $ docker run -it ubuntu bash hello_1 | hello_1 | Share images, automate workflows, and more with a free Docker ID: hello_1 | https://hub.docker.com/ hello_1 | hello_1 | For more examples and ideas, visit: hello_1 | https://docs.docker.com/engine/userguide/ hello_1 | oki2a24_hello_1 exited with code 0 $ $ docker-compose down Removing oki2a24_hello_1 ... done Removing network oki2a24_default $
おわりに
brew install docker-compose
で docker もインストールされます。ですので、これだけで良いのではないかと思ったのですけれども、brew cask docker
をしなければ動きませんでした><。
cask の方は、Docker.app がインストールされます。これを実行しなければ、docker が使えませんでした。
cask で無い方の docker を、起動する方法がわかれば、cask の Docker をインストールしなくても良いのでしょうか?
気になりますけれども、今回の手順で動きましたので、これでよしといたします。
次のページを見ますと、cask の docker のみで大丈夫のようですけれども、、、よくわかりません。
追記(2018年7月28日12時42分)
cask で無い方の docker、docker-compose のインストールは不要でした。cask でのインストーしても動かないと思っていたのは、おそらくインストール後に Docker を起動していなかったからです><。
以上です。