Docker for Windows

Linux でのインストール
# yum install docker
# systemctl start docker
# systemctl enable docker

以下はWindows上を想定 Dockerのサービス状態を確認する。

PS C:\Users\docker> docker info
Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 0
Server Version: 18.09.2
~(後略)~

Docker イメージの検索

> docker search httpd
NAME                                 DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
httpd                                The Apache HTTP Server Project                  2552                [OK]
centos/httpd                                                                         23                                      [OK]
centos/httpd-24-centos7              Platform for running Apache httpd 2.4 or bui…   22

イメージの入手

> docker pull httpd
Using default tag: latest
latest: Pulling from library/httpd
f5d23c7fed46: Pull complete
b083c5fd185b: Pull complete
bf5100a89e78: Pull complete
98f47fcaa52f: Pull complete
622a9dd8cfed: Pull complete
Digest: sha256:8bd76c050761610773b484e411612a31f299dbf7273763103edbda82acd73642
Status: Downloaded newer image for httpd:latest

イメージの一覧を表示する

> docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
httpd               latest              ee39f68eb241        4 days ago          154MB

コンテナを生成して起動

> docker run -d -p 8080:80 httpd(-d: デタッチド=バックグラウンドで実行 --name=: コンテナに名前を付ける -p 自ホストの8080をコンテナのポート80と繋ぐ)
> docker run -d --name=httpd -p 80:80 httpd
29f740bde604b7716865b96c94ef166f0835b3598e70088804fa77b5a8648599
PS C:\Users\admin\docker-amp> docker ps
CONTAINER ID        IMAGE               COMMAND              CREATED             STATUS              PORTS                NAMES
29f740bde604        httpd               "httpd-foreground"   6 seconds ago       Up 4 seconds        0.0.0.0:8080->80/tcp   httpd

f:id:hirose-test:20190717183844p:plain

コンテナの一覧を表示する

> docker ps -a(-a : 停止中のコンテナも表示する)
CONTAINER ID        IMAGE               COMMAND              CREATED             STATUS              PORTS                  NAMES
35651e0dbea0        httpd               "httpd-foreground"   8 minutes ago       Up 8 minutes        0.0.0.0:8080->80/tcp   httpd

コンテナの停止

> docker stop 356
356

コンテナの削除

> docker rm 356
356

ローカルディレクトリとマウントしたコンテナを生成

コンテナの起動

> docker start 7dd
7dd
> docker rmi ee39
Untagged: httpd:latest
Untagged: httpd@sha256:8bd76c050761610773b484e411612a31f299dbf7273763103edbda82acd73642
Deleted: sha256:ee39f68eb241fd811887da7e21425ac657074363daa9969b9519504785f5d60d
Deleted: sha256:58196fbec21e78d5358fbc70beb15f0c88876cd90b69e7b1ddaf4704555dd740
Deleted: sha256:8f7378bcc6ba3317d1366fa79733e4a8b703d7cde181f671229a6619116477a8
Deleted: sha256:43c1dcceb2782c203ab2b2a5229f4938a2a05fbc70b8508f3de668434422c264
Deleted: sha256:912caf7e400db91ab190309fdf9baa15cf42574a3eefe1e1a4c6ab4a963742ff
Deleted: sha256:d8a33133e477d367977987129313d9072e0ec80894ed4c52c2d88186f354c29a

起動中のコンテナでコマンドを実行する

> docker exec -it 40b bash (-i:インタラクティブモード。-t : 仮想端末の割り当て)
root@40b604da6f3d:/usr/local/apache2#

root@40b604da6f3d:/usr/local/apache2# cat /etc/debian_version
10.0
root@40b604da6f3d:/usr/local/apache2# cat /etc/issue
Debian GNU/Linux 10 \n \l
> docker stop f46
f46
> docker rm f46
f46
> docker run -d --name apache -p 8081:80 httpd
95df079be5569ebd9cdcd9b9c10500081d1d709a7ef7ca04779d35aba8ef7cdc
> docker ps -a
CONTAINER ID        IMAGE               COMMAND              CREATED             STATUS              PORTS                  NAMES
95df079be556        httpd               "httpd-foreground"   9 seconds ago       Up 7 seconds        0.0.0.0:8081->80/tcp   apache
> docker stop apache
apache
> docker rm apache
apache
> docker run -d --name apache -p 8081:80 -v "$(pwd):/usr/local/apache2/htdocs/" httpd
608f62e1a99f177d48945e0ba25179423c99b7faae50d9894ab10b8b94825d4e
> docker help

Usage:  docker [OPTIONS] COMMAND

A self-sufficient runtime for containers

Options:
      --config string      Location of client config files (default
                           "C:\\Users\\admin\\.docker")
  -D, --debug              Enable debug mode
  -H, --host list          Daemon socket(s) to connect to
  -l, --log-level string   Set the logging level
                           ("debug"|"info"|"warn"|"error"|"fatal")
                           (default "info")
      --tls                Use TLS; implied by --tlsverify
      --tlscacert string   Trust certs signed only by this CA (default
                           "C:\\Users\\admin\\.docker\\ca.pem")
      --tlscert string     Path to TLS certificate file (default
                           "C:\\Users\\admin\\.docker\\cert.pem")
      --tlskey string      Path to TLS key file (default
                           "C:\\Users\\admin\\.docker\\key.pem")
      --tlsverify          Use TLS and verify the remote
  -v, --version            Print version information and quit

Management Commands:
  builder     Manage builds
  config      Manage Docker configs
  container   Manage containers
  image       Manage images
  network     Manage networks
  node        Manage Swarm nodes
  plugin      Manage plugins
  secret      Manage Docker secrets
  service     Manage services
  stack       Manage Docker stacks
  swarm       Manage Swarm
  system      Manage Docker
  trust       Manage trust on Docker images
  volume      Manage volumes

Commands:
  attach      Attach local standard input, output, and error streams to a running container
  build       Build an image from a Dockerfile
  commit      Create a new image from a container's changes
  cp          Copy files/folders between a container and the local filesystem
  create      Create a new container
  diff        Inspect changes to files or directories on a container's filesystem
  events      Get real time events from the server
  exec        Run a command in a running container
  export      Export a container's filesystem as a tar archive
  history     Show the history of an image
  images      List images
  import      Import the contents from a tarball to create a filesystem image
  info        Display system-wide information
  inspect     Return low-level information on Docker objects
  kill        Kill one or more running containers
  load        Load an image from a tar archive or STDIN
  login       Log in to a Docker registry
  logout      Log out from a Docker registry
  logs        Fetch the logs of a container
  pause       Pause all processes within one or more containers
  port        List port mappings or a specific mapping for the container
  ps          List containers
  pull        Pull an image or a repository from a registry
  push        Push an image or a repository to a registry
  rename      Rename a container
  restart     Restart one or more containers
  rm          Remove one or more containers
  rmi         Remove one or more images
  run         Run a command in a new container
  save        Save one or more images to a tar archive (streamed to STDOUT by default)
  search      Search the Docker Hub for images
  start       Start one or more stopped containers
  stats       Display a live stream of container(s) resource usage statistics
  stop        Stop one or more running containers
  tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
  top         Display the running processes of a container
  unpause     Unpause all processes within one or more containers
  update      Update configuration of one or more containers
  version     Show the Docker version information
  wait        Block until one or more containers stop, then print their exit codes

Run 'docker COMMAND --help' for more information on a command.
PS C:\Users\admin> docker top
"docker top" requires at least 1 argument.
See 'docker top --help'.

Usage:  docker top CONTAINER [ps OPTIONS]

Display the running processes of a container
/* -----codeの行番号----- */