LoginSignup
5
8

More than 3 years have passed since last update.

Homebrew で macOS に Docker をインストールして Hello world

Last updated at Posted at 2019-08-09

概要

  • Homebrew で macOS に Docker をインストールする
  • Docker が公式に提供している hello-world イメージをダウンロードしてコンテナを作成・起動する

環境

  • macOS Mojave

Homebrew で Docker をインストール

$ brew cask install docker
==> Satisfying dependencies
==> Downloading https://download.docker.com/mac/stable/37199/Docker.dmg
######################################################################## 100.0%
==> Verifying SHA-256 checksum for Cask 'docker'.
==> Installing Cask docker
==> Moving App 'Docker.app' to '/Applications/Docker.app'.
🍺  docker was successfully installed!

インストールしたけど docker コマンドがみつからない

$ docker --version
-bash: docker: command not found

Docker.app を起動する

Docker.app を起動することで docker コマンドが使えるようになる。

$ open /Applications/Docker.app

Docker ID は必要でなければ作成しなくてよい。

docker.png

「Docker Desktop is now up and running!」

これで docker コマンドが使えるようになった。

$ docker --version
Docker version 19.03.1, build 74b1e89

$ which docker
/usr/local/bin/docker

$ ls -la /usr/local/bin/docker
lrwxr-xr-x  1 root  admin  54  8  9 09:44 /usr/local/bin/docker -> /Applications/Docker.app/Contents/Resources/bin/docker

インストールされる Docker の情報

インストールされる Docker のバージョン等は Homebrew Cask のソースコードに載っている。

homebrew-cask/docker.rb at 5037705e8ed028ae1a45c6fb7d6b94e5fb0cc8d8 · Homebrew/homebrew-cask · GitHub

  if MacOS.version <= :el_capitan
    version '18.06.1-ce-mac73,26764'
    sha256 '3429eac38cf0d198039ad6e1adce0016f642cdb914a34c67ce40f069cdb047a5'
  else
    version '2.1.0.1,37199'
    sha256 'b638696702d88308a49c5ff985055b6bb329afcfcd0c3ffda1c3fed6e078d01a'
  end

Docker 公式の Hello world を実行する

Docker が公式に提供している hello-world イメージがある。

hello-world - Docker Hub

Docker Official Images
Hello World! (an example of minimal Dockerization)

docker run で hello-world イメージをダウンロードして、イメージから新しいコンテナを作成して起動するとメッセージが表示される。

$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete 
Digest: sha256:6540fc08ee6e6b7b63468dc3317e3303aae178cb8a45ed3123180328bcc1d20f
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/

docker images で作成した Docker イメージ一覧を確認。

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              fce289e99eb9        7 months ago        1.84kB

docker ps -a でコンテナ一覧を表示。

$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
f2d8db4444fa        hello-world         "/hello"            7 minutes ago       Exited (0) 7 minutes ago                       pensive_chaum

docker rm でコンテナIDを指定してコンテナを削除。

$ docker rm f2d8db4444fa
f2d8db4444fa

参考資料

5
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
8