Docker Common Commands

来源:互联网 发布:华为财务共享中心 知乎 编辑:程序博客网 时间:2024/06/01 09:36

PS C:\Users\samstevens> docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES


Here is an example of command output for docker version.

   PS C:\Users\Vicky> docker version   Client:   Version:      1.12.0   API version:  1.24   Go version:   go1.6.3   Git commit:   8eab29e   Built:        Thu Jul 28 21:04:48 2016   OS/Arch:      windows/amd64   Experimental: true   Server:   Version:      1.12.0   API version:  1.24   Go version:   go1.6.3   Git commit:   8eab29e   Built:        Thu Jul 28 21:04:48 2016   OS/Arch:      linux/amd64   Experimental: true

Here is an example of command output for docker info

   PS C:\Users\Vicky> docker info   Containers: 0   Running: 0   Paused: 0   Stopped: 0   Images: 0   Server Version: 1.12.0   Storage Driver: aufs   Root Dir: /var/lib/docker/aufs   Backing Filesystem: extfs   Dirs: 0   Dirperm1 Supported: true   Logging Driver: json-file   Cgroup Driver: cgroupfs   Plugins:   Volume: local   Network: host bridge null overlay   Swarm: inactive   Runtimes: runc   Default Runtime: runc   Security Options: seccomp   Kernel Version: 4.4.16-moby   Operating System: Alpine Linux v3.4   OSType: linux   Architecture: x86_64   CPUs: 2   Total Memory: 1.95 GiB   Name: moby   ID: BG6O:2VMH:OLNV:DDLF:SCSV:URRH:BW6M:INBW:OLAC:J7PX:XZVL:ADNB   Docker Root Dir: /var/lib/docker   Debug Mode (client): false   Debug Mode (server): false   Registry: https://index.docker.io/v1/   Experimental: true   Insecure Registries:   127.0.0.0/8

For the pièce de résistance, start a Dockerized webserver with this command:

   docker run -d -p 80:80 --name webserver nginx

This will download the nginx container image and start it. Here is the output of running this command in a powershell.

   PS C:\Users\samstevens> docker run -d -p 80:80 --name webserver nginx   Unable to find image 'nginx:latest' locally   latest: Pulling from library/nginx   fdd5d7827f33: Pull complete   a3ed95caeb02: Pull complete   716f7a5f3082: Pull complete   7b10f03a0309: Pull complete   Digest: sha256:f6a001272d5d324c4c9f3f183e1b69e9e0ff12debeb7a092730d638c33e0de3e   Status: Downloaded newer image for nginx:latest   dfe13c68b3b86f01951af617df02be4897184cbf7a8b4d5caf1c3c5bd3fc267f
$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                         NAMES
5437af667b91        nginx               "nginx -g 'daemon off"   15 minutes ago      Up 2 seconds        0.0.0.0:80->80/tcp, 443/tcp   webserver

$ docker-machine ls
NAME      ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER    ERRORS
default   *        virtualbox   Running   tcp://192.168.99.100:2376           v1.12.0

Try to access the http://192.168.99.100:80 <--- 192.168.99.100 is the virtualbox ip which has been assigned by your current OS.




Stop or remove containers and images.

The nginx webserver will continue to run in the container on that port until you stop and/or remove the container. If you want to stop the webserver, type: docker stop webserver and start it again with docker start webserver.

To stop and remove the running container with a single command, type: docker rm -f webserver. This will remove the container, but not the nginx image. You can list local images with docker images. You might want to keep some images around so that you don’t have to pull them again from Docker Hub. To remove an image you no longer need, use docker rmi <imageID>|<imageName>. For example, docker rmi nginx.


$ docker stop webserver
webserver


 If you are using a Docker Machine VM, you can use the docker-machine ip MACHINE_NAME to get the IP address.

$ docker-machine ip default
192.168.99.100


$ docker pull python:2.7
2.7: Pulling from library/python
6a5a5368e0c2: Already exists
7b9457ec39de: Already exists
ff18e19c2db4: Already exists
6a3d69edbe90: Already exists
766692404ca7: Pulling fs layer
0ea0cc832151: Pulling fs layer
f80b8049666f: Pulling fs layer
766692404ca7: Verifying Checksum
766692404ca7: Download complete
766692404ca7: Pull complete

f80b8049666f: Verifying Checksum
f80b8049666f: Download complete
0ea0cc832151: Verifying Checksum
0ea0cc832151: Download complete
0ea0cc832151: Pull complete
f80b8049666f: Pull complete
Digest: sha256:113d08e6f7910d0db137bc46546b34e5efea255f773b50d43f2edbe7f1f7824e
Status: Downloaded newer image for python:2.7


$ docker ps -a
CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS                        PORTS               NAMES
8a7d234e4905        ubuntu                      "/bin/bash"              8 minutes ago       Exited (0) 8 minutes ago                          nauseous_bell
9c80fba8a8ba        consol/tomcat-8.0           "/bin/sh -c /opt/tomc"   26 minutes ago      Exited (137) 19 minutes ago                       tomcat8_3
20aac88cb6fc        consol/tomcat-8.0           "/bin/sh -c /opt/tomc"   26 minutes ago      Exited (137) 19 minutes ago                       tomcat8_2
1ad47fb50707        consol/tomcat-8.0           "/bin/sh -c /opt/tomc"   29 minutes ago      Created                                           tomcat8_4
c6ea7a789710        consol/tomcat-8.0           "/bin/sh -c /opt/tomc"   32 minutes ago      Exited (137) 18 minutes ago                       tomcat8_1
f86f3f6ec74d        ubuntu                      "/bin/bash"              2 hours ago         Exited (1) 2 hours ago                            goofy_banach
1bc41dd6ef6d        consol/tomcat-8.0           "/bin/sh -c /opt/tomc"   8 hours ago         Exited (137) 28 minutes ago                       tomcat_server
c204cae8d6e3        dockercomposeproject1_web   "python manage.py run"   2 days ago          Exited (0) 2 days ago                             dockercomposeproject1_web_1
f7273aa790ba        dockercomposeproject1_web   "django-admin.py star"   2 days ago          Exited (0) 2 days ago                             dockercomposeproject1_web_run_1
9ab96bcaef70        postgres                    "/docker-entrypoint.s"   2 days ago          Exited (0) 2 days ago                             dockercomposeproject1_db_1
5437af667b91        nginx                       "nginx -g 'daemon off"   2 days ago          Exited (0) 10 hours ago                           webserver
b9f61eb18faf        ubuntu                      "bash"                   2 days ago          Exited (0) 2 days ago                             admiring_roentgen
6ee08ab15842        ubuntu                      "bash"                   2 days ago          Exited (0) 2 days ago                             stupefied_hoover
a0ed83a2246b        hello-world                 "/hello"                 2 days ago          Exited (0) 2 days ago                             boring_yonath
bb4c0b152003        hello-world                 "/hello"                 2 days ago          Exited (0) 2 days ago                             goofy_liskov
f823c78eeb0b        ubuntu                      "echo larry testing h"   3 days ago          Exited (0) 3 days ago                             pensive_roentgen
3bfa502500e9        ubuntu                      "/bin/bash"              3 days ago          Exited (0) 3 days ago                             adoring_feynman
9805bb7fc9e3        ubuntu                      "/bin/bash"              3 days ago          Exited (0) 3 days ago                             berserk_einstein
7c81dca72690        ubuntu                      "/bin/bash"              3 days ago          Exited (0) 3 days ago                             determined_cori
4f8bd2fca134        ubuntu                      "echo larry here test"   5 days ago          Exited (0) 5 days ago                             naughty_mirzakhani
47d14cd32884        learn/tutorial              "ls -lrt"                5 days ago          Exited (0) 5 days ago                             peaceful_spence
05c04fc31bfb        learn/tutorial              "get"                    5 days ago          Created                                           hopeful_brahmagupta
fa1b33919915        learn/tutorial              "curl"                   5 days ago          Created                                           jolly_sammet
fa8e54e48bc2        learn/tutorial              "ping"                   5 days ago          Created                                           gloomy_meninsky
c12f2e789d8b        learn/tutorial              "ls -lrt"                5 days ago          Exited (0) 5 days ago                             hungry_yonath
03b2428e076d        centos                      "tail -10 ks-script-V"   5 days ago          Exited (0) 5 days ago                             tiny_ramanujan
024d3c8d0ef6        centos                      "ls -lrt tmp"            5 days ago          Exited (0) 5 days ago                             zen_kalam
7c1c068cf670        centos                      "ls -lrt dev"            5 days ago          Exited (0) 5 days ago                             goofy_pasteur
fe29f745c889        centos                      "tail -10 anaconda-po"   5 days ago          Exited (0) 5 days ago                             modest_wright
ecda61d953c8        centos                      "ls -lrt"                5 days ago          Exited (0) 5 days ago                             focused_mclean
cdc7207ba014        centos                      "mkdir larry"            5 days ago          Exited (0) 5 days ago                             big_torvalds
82deb8786fdc        centos                      "pwd"                    5 days ago          Exited (0) 5 days ago                             evil_almeida
51eaff1f37fc        centos                      "wget"                   5 days ago          Created                                           suspicious_knuth
bac48a69e9be        centos                      "ls -lrt"                5 days ago          Exited (0) 5 days ago                             clever_shirley
bab4e5392d23        centos                      "-version"               5 days ago          Created                                           high_pasteur


$ docker ps -h
Flag shorthand -h has been deprecated, please use --help


Usage:  docker ps [OPTIONS]


List containers


Options:
  -a, --all             Show all containers (default shows just running)
  -f, --filter value    Filter output based on conditions provided (default [])
      --format string   Pretty-print containers using a Go template
      --help            Print usage
  -n, --last int        Show n last created containers (includes all states) (default -1)
  -l, --latest          Show the latest created container (includes all states)
      --no-trunc        Don't truncate output
  -q, --quiet           Only display numeric IDs
  -s, --size            Display total file sizes

0 0
原创粉丝点击