2022/09/05 Updated by

Docker Tutorial


[Up] Japanese English

チュートリアルとして公式の 「Docker for Windows を始めよう」 を試す。

インストールの確認

  1. Windows 上に "Docker Desktop" がインストールしてある。
  2. PowerShell を開く
  3. PS C:\Users\nitta> docker --version
    Docker version 20.10.17, build 100c701
    
  4. hellow-world Image を Docker Hub から取得し、コンテナとして実行する。
  5. PS C:\Users\nitta> docker run hello-world
    
    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 run hello-world
    
  6. Image の一覧を表示する。
  7. PS C:\Users\nitta> docker image ls
    REPOSITORY                  TAG             IMAGE ID       CREATED         SIZE
    maluuba/newsqa              latest          6d86de301d59   10 months ago   2.43GB
    hello-world                 latest          feb5d9fea6a5   11 months ago   13.3kB
    nvcr.io/nvidia/tensorflow   21.08-tf2-py3   2abe022b55d1   12 months ago   11.5GB
    ai_security                 latest          46462b1c6de0   16 months ago   3.1GB
    docker/getting-started      latest          3ba8f2ff0727   17 months ago   27.9MB
    
  8. Container 一覧を表示する
  9. PS C:\Users\nitta> docker container ls --all
    CONTAINER ID   IMAGE                                     COMMAND                  CREATED             STATUS                         PORTS                                        NAMES
    81656de23823   hello-world                               "/hello"                 3 minutes ago       Exited (0) 3 minutes ago                                                    focused_diffie
    257568afa1fc   hello-world                               "/hello"                 About an hour ago   Exited (0) About an hour ago                                                hungry_pare
    22d367464908   nvcr.io/nvidia/tensorflow:21.08-tf2-py3   "/usr/local/bin/nvid…"   3 hours ago         Up 44 minutes                  6006/tcp, 6064/tcp, 0.0.0.0:8888->8888/tcp   eager_northcutt
    7bfc59e893ff   docker/getting-started                    "/docker-entrypoint.…"   17 months ago       Exited (0) 17 months ago
    

アプリケーションの探索

  1. Ubuntu OS のイメージを取得し、作成したコンテナ内でターミナルを実行する。
  2. PS C:\Users\nitta> docker run --interactive --tty ubuntu bash
    Unable to find image 'ubuntu:latest' locally
    latest: Pulling from library/ubuntu
    2b55860d4c66: Pull complete
    Digest: sha256:20fa2d7bb4de7723f542be5923b06c4d704370f0390e4ae9e1c833c8785644c1
    Status: Downloaded newer image for ubuntu:latest
    root@81d036afbfc1:/# hostname
    81d036afbfc1
    root@81d036afbfc1:/# exit
    exit
    PS C:\Users\nitta>
    
  3. コンテナの一覧を表示する。
  4. PS C:\Users\nitta> docker container ls --all
    CONTAINER ID   IMAGE                                     COMMAND                  CREATED          STATUS                          PORTS                                        NAMES
    81d036afbfc1   ubuntu                                    "bash"                   2 minutes ago    Exited (0) About a minute ago                                                wizardly_cori
    81656de23823   hello-world                               "/hello"                 47 minutes ago   Exited (0) 47 minutes ago                                                    focused_diffie
    257568afa1fc   hello-world                               "/hello"                 2 hours ago      Exited (0) 2 hours ago                                                       hungry_pare
    22d367464908   nvcr.io/nvidia/tensorflow:21.08-tf2-py3   "/usr/local/bin/nvid…"   3 hours ago      Up About an hour                6006/tcp, 6064/tcp, 0.0.0.0:8888->8888/tcp   eager_northcutt
    7bfc59e893ff   docker/getting-started                    "/docker-entrypoint.…"   17 months ago    Exited (0) 17 months ago                                                     gifted_rosalind
    
  5. Docker 化した nginx WWW server を取得し、実行する。名前は webserver とする。
  6. PS C:\Users\nitta> docker run --detach --publish 80:80 --name webserver nginx
    Unable to find image 'nginx:latest' locally
    latest: Pulling from library/nginx
    7a6db449b51b: Pull complete
    ca1981974b58: Pull complete
    d4019c921e20: Pull complete
    7cb804d746d4: Pull complete
    e7a561826262: Pull complete
    7247f6e5c182: Pull complete
    Digest: sha256:b95a99feebf7797479e0c5eb5ec0bdfa5d9f504bc94da550c2f58e839ea6914f
    Status: Downloaded newer image for nginx:latest
    39da94d079e5820e49e5cc073067d1933aa27d7b6ce8601194c8f55884944942
    
  7. ブラウザで http://localhost:80/ にアクセスする。-publish n:m はホストのn番ポートをゲストのm番ポートへフォワーディングすることを意味する。
  8. PS C:\Users\nitta> docker container ls
    CONTAINER ID   IMAGE                                     COMMAND                  CREATED         STATUS         PORTS                                        NAMES
    39da94d079e5   nginx                                     "/docker-entrypoint.…"   4 minutes ago   Up 3 minutes   0.0.0.0:80->80/tcp                           webserver
    22d367464908   nvcr.io/nvidia/tensorflow:21.08-tf2-py3   "/usr/local/bin/nvid…"   3 hours ago     Up 2 hours     6006/tcp, 6064/tcp, 0.0.0.0:8888->8888/tcp   eager_northcutt
    
  9. 名前で指定して、実行中のコンテナを停止する。
  10. PS C:\Users\nitta> docker container stop webserver
    webserver
    
  11. 名前で指定して、停止中のコンテナを削除する。
  12. PS C:\Users\nitta> docker container rm focused_diffie hungry_pare
    focused_diffie
    hungry_pare
    PS C:\Users\nitta> docker container ls --all
    CONTAINER ID   IMAGE                                     COMMAND                  CREATED          STATUS                      PORTS                                        NAMES
    39da94d079e5   nginx                                     "/docker-entrypoint.…"   9 minutes ago    Exited (0) 3 minutes ago                                                 webserver
    81d036afbfc1   ubuntu                                    "bash"                   14 minutes ago   Exited (0) 13 minutes ago                                                wizardly_cori
    22d367464908   nvcr.io/nvidia/tensorflow:21.08-tf2-py3   "/usr/local/bin/nvid…"   4 hours ago      Up 2 hours                  6006/tcp, 6064/tcp, 0.0.0.0:8888->8888/tcp   eager_northcutt
    7bfc59e893ff   docker/getting-started                    "/docker-entrypoint.…"   17 months ago    Exited (0) 17 months ago                                                 gifted_rosalind
    

Docker Tutorials and Labs

Docker Tutorials and Labs