LoginSignup
14
9

More than 5 years have passed since last update.

Docker for Macをインストールしてみた

Last updated at Posted at 2017-12-22

概要

MacにDockerを入れてUbuntuが動いたっぽいことを確認するところまで。Qiita初投稿ということで記事の書き方を覚える。

環境

  • MacOSX 10.13.2 (High Sierra)
  • Docker for Mac 17.09.1-ce

手順

Docker for Macのダウンロード

以下のURLからダウンロード、インストール
https://store.docker.com/editions/community/docker-ce-desktop-mac

Dockerを起動

ウィンドウが立ち上がらないな・・・?と思っていたらいつの間にか上のメニューバーにいる。(画像は公式サイトから引用)
whale-in-menu-bar.png

ターミナルを起動してDockerのバージョン取得

ダウンロードページに"docker version"やってみろと書いてある。

Run docker version to check that you have the latest release installed.

やってみる。

$ docker version
Client:
 Version:      17.09.1-ce
 API version:  1.32
 Go version:   go1.8.3
 Git commit:   19e2cf6
 Built:        Thu Dec  7 22:22:25 2017
 OS/Arch:      darwin/amd64

Server:
 Version:      17.09.1-ce
 API version:  1.32 (minimum version 1.12)
 Go version:   go1.8.3
 Git commit:   19e2cf6
 Built:        Thu Dec  7 22:28:28 2017
 OS/Arch:      linux/amd64
 Experimental: true

バージョンは17.09.1-ceであることがわかった。

Hello Worldをやってみる

ダウンロードページに"docker run hello-world"やってみろと書いてある。

Run docker run hello-world to verify that Docker is pulling images and running as expected.

やってみる。

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

何やらHello Worldでやれたことが書いてある模様。これは新しくコンテナが作成されてその上で実行されているらしい。でもすぐに終わっちゃう。

Ubuntuを動かしてみる

先のhello-worldの結果にもっとすごいことやりたいなら以下の"docker run"をやってみろと書いてある。

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

やってみる。

$ docker run -it ubuntu bash
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
50aff78429b1: Pull complete 
f6d82e297bce: Pull complete 
275abb2c8a6f: Pull complete 
9f15a39356d6: Pull complete 
fc0342a94c89: Pull complete 
Digest: sha256:ec0e4e8bf2c1178e025099eed57c566959bb408c6b478c284c1683bc4298b683
Status: Downloaded newer image for ubuntu:latest
root@6b549c48deef:/#

なんかrootユーザのプロンプトでてきたぞ?ちなみにオプションの意味は以下。

docker run コマンドでコンテナを実行します。
ubuntu イメージを使って起動します。
-t フラグは新しいコンテナ内に疑似ターミナル (pseudo-tty) を割り当てます。
-i フラグはコンテナの標準入力 (STDIN)を取得し、双方向に接続できるようにします
bash 新しいコンテナで実行するコマンド

Ubuntu上で色々情報みてみる

  • lsコマンドを実行。なんかLinuxっぽいディレクトリ構造が見える。
root@6b549c48deef:/# ls
bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
boot  etc  lib   media  opt  root  sbin  sys  usr
  • OSバージョン取得。Ubuntuになっておる。。。
root@6b549c48deef:/# cat /etc/os-release 
NAME="Ubuntu"
VERSION="16.04.3 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.3 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial
  • exitでMacに戻る
root@ccc544abfcd9:/home# exit          
exit
$

とりあえず今日はここまで。

14
9
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
14
9