Dockerとは

マンガでわかるDocker ①
マンガでわかるDocker ②
を読んで、なんとなーく理解。とーっても分かりやすい。
 

DockerとVirtualBoxの用語など整理

VirtualBox Docker
Image(イメージ) Box(ボックス)
Container(コンテナ) VM(仮想マシン)
冪等性:高 冪等性:低?

 

DockerでHelloWorld

docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:b8ba256769a0ac28dd126d584e0a2011cd2877f3f76e093a7ae560f2a5301c00
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 image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              fce289e99eb9        9 months ago        1.84kB

docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES</pre>

補足
hello-worldは
“Hello from Docker!!” を表示するだけのイメージ

docker run
では
docker pull # イメージ取得
docker create # コンテナ生成
docker start # コンテナ起動
の3つをまとめておこなっている。

docker ps
起動中のコンテナがないのは
“Hello from Docker!!”を表示してすぐに引っ込むため
docker ps -a
とすると、停止中のコンテナも表示できる

DockerでAlpineを使ってみる

Alpineとは
超軽量なLinuxディストリビューションらしい
(CentOS=4GB, Ubuntu=700MB, Alpine=100MB)
パッケージ管理はapkコマンドを使う

DockerでAlpineを立ち上げる

docker pull alpine

docker image ls

docker create -it alpine
cb2296ec5c04810d31743d6b59d335985ebc674889ffb093b0dccc67a5305bda
# ======================================================================
docker create -it alpine
-i(Keep STDIN open even if not attached) ... 標準入力を開き続ける
-t(Allocate a pseudo-TTY) … 疑似ttyを割りあてる
# ======================================================================

docker start cb2296ec5c04810d31743d6b59d335985ebc674889ffb093b0dccc67a5305bda
cb2296ec5c04810d31743d6b59d335985ebc674889ffb093b0dccc67a5305bda

docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
cb2296ec5c04        alpine              "/bin/sh"           2 minutes ago       Up 38 seconds                                   interesting_newton
c6d7eda6b0b9        hello-world         "/hello"            26 minutes ago      Exited (0) 26 minutes ago                       blissful_bohr

docker stop cb2296ec5c04810d31743d6b59d335985ebc674889ffb093b0dccc67a5305bda
cb2296ec5c04810d31743d6b59d335985ebc674889ffb093b0dccc67a5305bda

docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                        PORTS               NAMES
cb2296ec5c04        alpine              "/bin/sh"           6 minutes ago       Exited (137) 20 seconds ago                       interesting_newton
c6d7eda6b0b9        hello-world         "/hello"            31 minutes ago      Exited (0) 31 minutes ago                         blissful_bohr

 

コンテナの名前変更

docker rename interesting_newton alpine1

docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                       PORTS               NAMES
cb2296ec5c04        alpine              "/bin/sh"           9 minutes ago       Exited (137) 2 minutes ago                       alpine1
c6d7eda6b0b9        hello-world         "/hello"            33 minutes ago      Exited (0) 33 minutes ago                        blissful_bohr

 

コンテナに入る

docker start alpine1

docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
cb2296ec5c04        alpine              "/bin/sh"           18 minutes ago      Up 7 seconds                            alpine1

docker exec -it alpine1 /bin/sh

/ # ls
bin    dev    etc    home   lib    media  mnt    opt    proc   root   run    sbin   srv    sys    tmp    usr    var

/ # exit
カテゴリー: 技術

0件のコメント

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です