docker 命令詳解

孤竹星發表於2015-09-08
docker attach  attach到一個執行中的容器

[root@localhost ~]# docker attach --help        //docker attach幫助
Usage: docker attach [OPTIONS] CONTAINER
Attach to a running container
  --help=false        Print usage
  --no-stdin=false    Do not attach STDIN
  --sig-proxy=true    Proxy all received signals to the process

[root@localhost ~]# docker ps  //檢視執行中的docker
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

[root@localhost ~]# docker run -d -t -i --name centostest centos:latest  執行名“centos:latest”映象啟動名為“centostest”容器
1ebe9c55d4692f39917f3c78cfed30573aa6f02e51b618274d0b39f090c9b91e

[root@localhost ~]# docker ps 
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
1ebe9c55d469        centos:latest       "/bin/bash"         40 seconds ago      Up 38 seconds                           centostest          
[root@localhost ~]# 
[root@localhost ~]# docker attach centostest     //attach 到容器centostest中

[root@1ebe9c55d469 /]# 先按ctrl + p 在按 ctrl+q  //退出容器,容器繼續執行

[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
1ebe9c55d469        centos:latest       "/bin/bash"         54 minutes ago      Up 53 minutes                           centostest          

[root@localhost ~]# docker attach centostest 

[root@1ebe9c55d469 home]# 
[root@1ebe9c55d469 home]# exit    //退出容器,容器停止執行
exit
[root@localhost ~]# 
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[root@localhost ~]#
 [root@localhost ~]# docker ps -a
CONTAINER ID        IMAGE                     COMMAND                CREATED             STATUS                           PORTS               NAMES
1ebe9c55d469        centos:latest             "/bin/bash"            57 minutes ago      Exited (0) 52 seconds ago                            centostest  
[root@localhost ~]# docker start centostest     //啟動“centostest” 容器
centostest
[root@localhost ~]# docker attach centostest 
[root@1ebe9c55d469 /]#
注意一點直接執行exit將會退出並終止容器執行,需要重新start後才能連線

docker build 從dockerfile中建立一個映象
[root@localhost ~]# docker build --help

Usage: docker build [OPTIONS] PATH | URL | -

Build a new image from the source code at PATH

  -c, --cpu-shares=0    CPU shares (relative weight)
  --cgroup-parent=      Optional parent cgroup for the container
  --cpu-period=0        Limit the CPU CFS (Completely Fair Scheduler) period
  --cpu-quota=0         Limit the CPU CFS (Completely Fair Scheduler) quota
  --cpuset-cpus=        CPUs in which to allow execution (0-3, 0,1)
  --cpuset-mems=        MEMs in which to allow execution (0-3, 0,1)
  -f, --file=           Name of the Dockerfile (Default is 'PATH/Dockerfile')
  --force-rm=false      Always remove intermediate containers
  --help=false          Print usage
  -m, --memory=         Memory limit
  --memory-swap=        Total memory (memory + swap), '-1' to disable swap
  --no-cache=false      Do not use cache when building the image
  --pull=false          Always attempt to pull a newer version of the image
  -q, --quiet=false     Suppress the verbose output generated by the containers
  --rm=true             Remove intermediate containers after a successful build
  -t, --tag=            Repository name (and optionally a tag) for the image


docker commit  從一個修改後的容器建立一個新的映象
[root@localhost ~]# docker commit --help

Usage: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]

Create a new image from a container's changes

  -a, --author=       Author (e.g., "John Hannibal Smith <hannibal@a-team.com>")  //提交作者
  -c, --change=[]     Apply Dockerfile instruction to the created image            //應用docker 指令建立映象
  --help=false        Print usage
  -m, --message=      Commit message
  -p, --pause=true    Pause container during commit

[root@localhost ~]# docker commit -a "soft test" -m "this is centostest container create image" -p centostest centcommit:v1.0.0
ce642745a4a78b7e64647ea55e8af812a3fc30d36976bd5f0bc5c5710dd83dd9

[root@localhost ~]# docker images    //檢視映象
REPOSITORY                TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centcommit                v1.0.0              ce642745a4a7        23 seconds ago      172.2 MB


docker cp
從一個容器檔案系統複製檔案/目錄到主機路徑
[root@localhost ~]# docker cp --help

Usage: docker cp [OPTIONS] CONTAINER:PATH HOSTDIR|-

Copy files/folders from a PATH on the container to a HOSTDIR on the host
running the command. Use '-' to write the data as a tar file to STDOUT.

  --help=false       Print usage

docker cp name:/container_path to_path
docker cp ID:/container_path to_path

將容器centostest容器中/home目錄下的aa檔案複製到本地/home下
docker cp centostest:/home/aa /home


[root@localhost ~]# docker attach centostest 

[root@1ebe9c55d469 home]# ll aa
-rw-r--r--. 1 root root 16 Sep  8 02:29 aa
[root@1ebe9c55d469 home]# cat aa
this is file aa
[root@1ebe9c55d469 home]# 

[root@localhost home]# docker cp centostest:/home/aa /home
[root@localhost home]# cat aa
this is file aa

docker create  建立一個新容器
[root@localhost ~]# docker create --help

Usage: docker create [OPTIONS] IMAGE [COMMAND] [ARG...]

Create a new container

  -a, --attach=[]             Attach to STDIN, STDOUT or STDERR
  --add-host=[]               Add a custom host-to-IP mapping (host:ip)
  --blkio-weight=0            Block IO (relative weight), between 10 and 1000
  -c, --cpu-shares=0          CPU shares (relative weight)
  --cap-add=[]                Add Linux capabilities
  --cap-drop=[]               Drop Linux capabilities
  --cgroup-parent=            Optional parent cgroup for the container
  --cidfile=                  Write the container ID to the file
  --cpu-period=0              Limit CPU CFS (Completely Fair Scheduler) period
  --cpu-quota=0               Limit the CPU CFS quota
  --cpuset-cpus=              CPUs in which to allow execution (0-3, 0,1)
  --cpuset-mems=              MEMs in which to allow execution (0-3, 0,1)
  --device=[]                 Add a host device to the container
  --dns=[]                    Set custom DNS servers
  --dns-search=[]             Set custom DNS search domains
  -e, --env=[]                Set environment variables
  --entrypoint=               Overwrite the default ENTRYPOINT of the image
  --env-file=[]               Read in a file of environment variables
  --expose=[]                 Expose a port or a range of ports
  -h, --hostname=             Container host name
  --help=false                Print usage
  -i, --interactive=false     Keep STDIN open even if not attached
  --ipc=                      IPC namespace to use
  -l, --label=[]              Set meta data on a container
  --label-file=[]             Read in a line delimited file of labels
  --link=[]                   Add link to another container
  --log-driver=               Logging driver for container
  --log-opt=[]                Log driver options
  --lxc-conf=[]               Add custom lxc options
  -m, --memory=               Memory limit
  --mac-address=              Container MAC address (e.g. 92:d0:c6:0a:29:33)
  --memory-swap=              Total memory (memory + swap), '-1' to disable swap
  --name=                     Assign a name to the container
  --net=bridge                Set the Network mode for the container
  --oom-kill-disable=false    Disable OOM Killer
  -P, --publish-all=false     Publish all exposed ports to random ports
  -p, --publish=[]            Publish a container's port(s) to the host
  --pid=                      PID namespace to use
  --privileged=false          Give extended privileges to this container
  --read-only=false           Mount the container's root filesystem as read only
  --restart=no                Restart policy to apply when a container exits
  --security-opt=[]           Security Options
  -t, --tty=false             Allocate a pseudo-TTY
  -u, --user=                 Username or UID (format: <name|uid>[:<group|gid>])
  --ulimit=[]                 Ulimit options
  --uts=                      UTS namespace to use
  -v, --volume=[]             Bind mount a volume
  --volumes-from=[]           Mount volumes from the specified container(s)
  -w, --workdir=              Working directory inside the container

[root@localhost ~]# docker create -it --name centcommittest centcommit:v1.0.0   //使用centcommit:v1.0.0映象建立一個名為centcommittest容器
24e3991b710c216135ae0c57d64619d57001c738a1e9b0dc0d73a8782dd09191
[root@localhost ~]# docker ps -a
CONTAINER ID        IMAGE                     COMMAND                CREATED              STATUS              PORTS                        NAMES
24e3991b710c        centcommit:v1.0.0         "/bin/bash"            7 seconds ago                                                         centcommittest    

root@localhost ~]# docker start centcommittest  //啟用新建的容器
centcommittest
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE                     COMMAND                CREATED              STATUS              PORTS                        NAMES
24e3991b710c        centcommit:v1.0.0         "/bin/bash"            19 seconds ago       Up 3 seconds                                     centcommittest  

使用docker create 命令新建的容器處於停止狀態使用docker start 啟動容器


docker diff 檢查容器中檔案的改變

[root@localhost ~]# docker diff --help

Usage: docker diff [OPTIONS] CONTAINER

Inspect changes on a container's filesystem

  --help=false       Print usage

[root@localhost ~]# docker diff centostest 
C /home
A /home/aa
C /root
A /root/.bash_history

docker diff id/name
diff會列出3種容器內檔案狀態變化(A --Add,D -Delete,C -Change)的列表清單,構建Imge的過程中需要的除錯指令。

docker events  Get real time events from the server

[root@localhost ~]# docker events --help 

Usage: docker events [OPTIONS]

Get real time events from the server

  -f, --filter=[]    Filter output based on conditions provided
  --help=false       Print usage
  --since=           Show all events created since timestamp
  --until=           Stream events until this timestamp

docker exec 直接在容器內執行命令

[root@localhost ~]# docker exec -ti centcommittest touch /home/exec
[root@localhost ~]# docker attach centcommittest 
[root@24e3991b710c /]# cd /home/
[root@24e3991b710c home]# ll
total 4
-rw-r--r--. 1 root root 1222 Sep  7 08:52 aa
-rw-r--r--. 1 root root    0 Sep  8 03:44 exec

docker export 歸檔容器內容

[root@localhost ~]# docker export --help

Usage: docker export [OPTIONS] CONTAINER

Export a filesystem as a tar archive (streamed to STDOUT by default)

  --help=false       Print usage
  -o, --output=      Write to a file, instead of STDOUT

root@localhost ~]# docker export centcommittest > /home/exp_centcommit.tar   //將容器centcommittest 匯出到//home/exp_centcommit.tar 
不論容器是否處於執行狀態export 可以匯出,可以將這些檔案傳輸到其他機器上,在其他機器上透過匯入命令實現容器的遷移。

docker history 顯示映象歷史資訊

[root@localhost home]# docker history --help

Usage: docker history [OPTIONS] IMAGE

Show the history of an image

  -H, --human=true     Print sizes and dates in human readable format
  --help=false         Print usage
  --no-trunc=false     Don't truncate output
  -q, --quiet=false    Only show numeric IDs

[root@localhost home]# docker history centcommit:v1.0.0 
IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
ce642745a4a7        About an hour ago   /bin/bash                                       1.272 kB            this is centostest container create image
7322fbe74aa5        11 weeks ago        /bin/sh -c #(nop) CMD ["/bin/bash"]             0 B                 
c852f6d61e65        11 weeks ago        /bin/sh -c #(nop) ADD file:82835f82606420c764   172.2 MB            
f1b10cd84249        4 months ago        /bin/sh -c #(nop) MAINTAINER The CentOS Proje   0 B          

docker images 列出映象

[root@localhost home]# docker images --help

Usage: docker images [OPTIONS] [REPOSITORY]

List images

  -a, --all=false      Show all images (default hides intermediate images)   //顯示所有的映象,
  --digests=false      Show digests    //顯示摘要
  -f, --filter=[]      Filter output based on conditions provided    //根據提供的條件過濾輸出
  --help=false         Print usage
  --no-trunc=false     Don't truncate output    //不截斷輸出,顯示ID所有字元,預設只顯示錢幾位
  -q, --quiet=false    Only show numeric IDs    //僅顯示IDs 

[root@localhost home]# docker images --no-trunc=true
REPOSITORY                TAG                 IMAGE ID                                                           CREATED             VIRTUAL SIZE
centcommit                v1.0.0              ce642745a4a78b7e64647ea55e8af812a3fc30d36976bd5f0bc5c5710dd83dd9   3 hours ago         172.2 MB

[root@localhost home]# docker images -q
ce642745a4a7
fafa35c3ae8c
57bca5139a13
06dd8be95164

[root@localhost home]# docker images --digests 
REPOSITORY                TAG                 DIGEST              IMAGE ID            CREATED             VIRTUAL SIZE
centcommit                v1.0.0              <none>              ce642745a4a7        3 hours ago         172.2 MB

docker import 從一個壓縮檔案中建立一個新檔案系統映象

[root@localhost home]# docker import  --help 

Usage: docker import [OPTIONS] URL|- [REPOSITORY[:TAG]]

Create an empty filesystem image and import the contents of the
tarball (.tar, .tar.gz, .tgz, .bzip, .tar.xz, .txz) into it, then
optionally tag it.

  -c, --change=[]    Apply Dockerfile instruction to the created image
  --help=false       Print usage

[root@localhost home]# ll
total 2098600
-rw-r--r--.  1 root  root          16 Sep  8 10:29 aa
-rw-r--r--.  1 root  root   179815424 Sep  8 11:57 exp_centcommit.tar

[root@localhost home]# cat exp_centcommit.tar | docker import - impcentos:v1.0.0
e579ab7d4917fbf6e040811f727217ab8cfc358f2de0b1bb158476c8392daff4
[root@localhost home]# docker images 
REPOSITORY                TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
impcentos                 v1.0.0              e579ab7d4917        19 seconds ago      172.2 MB

docker info  顯示系統資訊

[root@localhost ~]# docker info 
Containers: 3
Images: 44
Storage Driver: devicemapper
 Pool Name: docker-253:0-393330-pool
 Pool Blocksize: 65.54 kB
 Backing Filesystem: extfs
 Data file: /dev/loop0
 Metadata file: /dev/loop1
 Data Space Used: 5.159 GB
 Data Space Total: 107.4 GB
 Data Space Available: 14.05 GB
 Metadata Space Used: 4.653 MB
 Metadata Space Total: 2.147 GB
 Metadata Space Available: 2.143 GB
 Udev Sync Supported: true
 Deferred Removal Enabled: false
 Data loop file: /var/lib/docker/devicemapper/devicemapper/data
 Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
 Library Version: 1.02.93-RHEL7 (2015-01-28)
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 3.10.0-229.7.2.el7.x86_64
Operating System: CentOS Linux 7 (Core)
CPUs: 2
Total Memory: 1.462 GiB
Name: localhost.localdomain
ID: C6AM:P5S3:Y6W7:FDLM:2AKE:XV6D:DA57:ULYT:KLJK:3A7M:INJG:FYF7
Username: loneboo
Registry: />
docker  inspect  返回容器或映象的底層資訊

[root@localhost ~]# docker inspect  --help

Usage: docker inspect [OPTIONS] CONTAINER|IMAGE [CONTAINER|IMAGE...]

Return low-level information on a container or image

  -f, --format=      Format the output using the given go template
  --help=false       Print usage
[root@localhost ~]# docker inspect centcommittest 
[
{
    "Id": "24e3991b710c216135ae0c57d64619d57001c738a1e9b0dc0d73a8782dd09191",
    "Created": "2015-09-08T03:21:42.199841832Z",
    "Path": "/bin/bash",
    "Args": [],
    "State": {
        "Running": true,
        "Paused": false,
        "Restarting": false,
        "OOMKilled": false,
....

[root@localhost ~]# docker inspect -f {{".Id"}} centcommittest     //如果只要其中一項內容時,使用-f引數來制定。如獲取Id資訊:
24e3991b710c216135ae0c57d64619d57001c738a1e9b0dc0d73a8782dd09191

docker kill kill掉一個執行的容器

[root@localhost ~]# docker kill --help 

Usage: docker kill [OPTIONS] CONTAINER [CONTAINER...]

Kill a running container using SIGKILL or a specified signal

  --help=false         Print usage
  -s, --signal=KILL    Signal to send to the container  //傳送資訊通知容器

docker kill name/id

docker load Load an image from a tar archive

[root@localhost ~]# docker load --help 

Usage: docker load [OPTIONS]

Load an image from a tar archive on STDIN

  --help=false       Print usage
  -i, --input=       Read from a tar archive file, instead of STDIN

[root@localhost home]#docker load --input centoscommittest.tar

docker load<centoscommittest.tar

docker logs  獲取容器的操作日誌

[root@localhost home]# docker logs --help 

Usage: docker logs [OPTIONS] CONTAINER

Fetch the logs of a container

  -f, --follow=false        Follow log output
  --help=false              Print usage
  --since=                  Show logs since timestamp
  -t, --timestamps=false    Show timestamps
  --tail=all                Number of lines to show from the end of the logs

docker logs ID/NAME

docker pause 暫停所有在容器中的程式

docker pause ID/NAME

docker ps 列出容器

[root@localhost home]# docker ps --help 

Usage: docker ps [OPTIONS]

List containers

  -a, --all=false       Show all containers (default shows just running)
  --before=             Show only container created before Id or Name
  -f, --filter=[]       Filter output based on conditions provided
  --help=false          Print usage
  -l, --latest=false    Show the latest created container, include non-running
  -n=-1                 Show n last created containers, include non-running
  --no-trunc=false      Don't truncate output
  -q, --quiet=false     Only display numeric IDs
  -s, --size=false      Display total file sizes
  --since=              Show created since Id or Name, include non-running

[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
e1ff99169e66        nginx               "/bin/bash"         29 minutes ago      Up 26 minutes       80/tcp, 443/tcp     elated_goldstine  


列出所有容器  
[root@localhost ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                        PORTS               NAMES
e1ff99169e66        nginx               "/bin/bash"         29 minutes ago      Up 26 minutes                 80/tcp, 443/tcp     elated_goldstine    
ae3754694598        centos              "/bin/bash"         3 hours ago         Exited (137) 18 minutes ago                       dreamy_fermat       
88df7394ce1a        hello-world         "/hello"            3 weeks ago         Exited (0) 30 minutes ago  

docker pull 從Docker 註冊伺服器上下載一個映象或資源庫

[root@localhost home]# docker pull --help 

Usage: docker pull [OPTIONS] NAME[:TAG|@DIGEST]

Pull an image or a repository from the registry

  -a, --all-tags=false    Download all tagged images in the repository
  --help=false            Print usage

docker pull name


docker push 上傳一個映象或資源庫到Docker註冊伺服器

注:不能直接使用 docker push job1,所有推送命令的格式必須是 docker push <user>/<repo_name>,不加 <user> 無法推送到 Docker registry。

docker rename 重新命名一個存在的容器

docker rename old_name new_name

docker restart 重啟一個執行的容器

[root@localhost home]# docker ps
CONTAINER ID        IMAGE                     COMMAND                CREATED             STATUS              PORTS                        NAMES
1ebe9c55d469        centos:latest             "/bin/bash"            22 hours ago        Up 21 hours                                      centostest          
8cd45d2ffcad        wnameless/oracle-xe-11g   "/bin/sh -c '/usr/sb   10 days ago         Up 3 hours          22/tcp, 1521/tcp, 8080/tcp   oracle11g           
[root@localhost home]# docker restart centostest 
centostest

docker rm  刪除一個或多個容器

docker rm id/name

-f,--force=false:強制終止並刪除一個執行中的容器
-l,--link=false:刪除容器的連線,但保留容器
-v,--volumes=false:刪除容器掛載的資料卷

docker rmi 刪除一個或多個映象

docker rmi id/name

docker run 執行一個新的容器

[root@localhost home]# docker run --help 

Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

Run a command in a new container

  -a, --attach=[]             Attach to STDIN, STDOUT or STDERR
  --add-host=[]               Add a custom host-to-IP mapping (host:ip)
  --blkio-weight=0            Block IO (relative weight), between 10 and 1000
  -c, --cpu-shares=0          CPU shares (relative weight)
  --cap-add=[]                Add Linux capabilities
  --cap-drop=[]               Drop Linux capabilities
  --cgroup-parent=            Optional parent cgroup for the container
  --cidfile=                  Write the container ID to the file
  --cpu-period=0              Limit CPU CFS (Completely Fair Scheduler) period
  --cpu-quota=0               Limit the CPU CFS quota
  --cpuset-cpus=              CPUs in which to allow execution (0-3, 0,1)
  --cpuset-mems=              MEMs in which to allow execution (0-3, 0,1)
  -d, --detach=false          Run container in background and print container ID
  --device=[]                 Add a host device to the container
  --dns=[]                    Set custom DNS servers
  --dns-search=[]             Set custom DNS search domains
  -e, --env=[]                Set environment variables
  --entrypoint=               Overwrite the default ENTRYPOINT of the image
  --env-file=[]               Read in a file of environment variables
  --expose=[]                 Expose a port or a range of ports
  -h, --hostname=             Container host name
  --help=false                Print usage
  -i, --interactive=false     Keep STDIN open even if not attached
  --ipc=                      IPC namespace to use
  -l, --label=[]              Set meta data on a container
  --label-file=[]             Read in a line delimited file of labels
  --link=[]                   Add link to another container
  --log-driver=               Logging driver for container
  --log-opt=[]                Log driver options
  --lxc-conf=[]               Add custom lxc options
  -m, --memory=               Memory limit
  --mac-address=              Container MAC address (e.g. 92:d0:c6:0a:29:33)
  --memory-swap=              Total memory (memory + swap), '-1' to disable swap
  --name=                     Assign a name to the container
  --net=bridge                Set the Network mode for the container
  --oom-kill-disable=false    Disable OOM Killer
  -P, --publish-all=false     Publish all exposed ports to random ports
  -p, --publish=[]            Publish a container's port(s) to the host
  --pid=                      PID namespace to use
  --privileged=false          Give extended privileges to this container
  --read-only=false           Mount the container's root filesystem as read only
  --restart=no                Restart policy to apply when a container exits
  --rm=false                  Automatically remove the container when it exits
  --security-opt=[]           Security Options
  --sig-proxy=true            Proxy received signals to the process
  -t, --tty=false             Allocate a pseudo-TTY
  -u, --user=                 Username or UID (format: <name|uid>[:<group|gid>])
  --ulimit=[]                 Ulimit options
  --uts=                      UTS namespace to use
  -v, --volume=[]             Bind mount a volume
  --volumes-from=[]           Mount volumes from the specified container(s)
  -w, --workdir=              Working directory inside the container

docker run -t -i ubuntu /bin/bash
檢查本地是否存在制定的映象,不存在從公有倉庫下載
利用映象建立並啟動一個容器
分配一個檔案系統,並在只讀的映象層外面掛著一層可讀寫層
從宿主主機配置的網橋介面中橋接一個虛擬介面到容器中去
從地址池配置一個IP地址給容器
執行使用者指定的應用程式
執行完畢後容器被終止。

-t:Docker分配一個偽終端並繫結到容器的標準輸入上,
-i:讓容器的標準輸入保持開啟。
對於建立的bash容器,當使用exit命令退出之後,容器就自動處於終止狀態了,這是因為對於Docker容器來說,當執行的應用退出後,容器也就沒有繼續執行的必要了。
-d:讓Docker容器在後臺以守護狀(Daemonized)形式執行

docker save 儲存一個映象到一個歸檔檔案

docker save -o centoscommittest.tar centoscommittest:latest     // 歸檔centoscommittest:latest映象至centoscommittest.tar

docker search 在Docker Hub上搜尋一個映象

[root@localhost home]# docker search hello-world
NAME                                     DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
hello-world                              Hello World! (an example of minimal Docker...   19        [OK]       
tutum/hello-world                        Image to test docker deployments. Has Apac...   12                   [OK]

docker start 啟動一個已停止的容器

docker start id/name
[root@localhost home]# docker ps -a
CONTAINER ID        IMAGE                     COMMAND                CREATED             STATUS                           PORTS                        NAMES
24e3991b710c        centcommit:v1.0.0         "/bin/bash"            4 hours ago         Exited (137) About an hour ago                                centcommittest      
1ebe9c55d469        centos:latest             "/bin/bash"            23 hours ago        Up 50 minutes                                                 centostest          
8cd45d2ffcad        wnameless/oracle-xe-11g   "/bin/sh -c '/usr/sb   10 days ago         Up 4 hours                       22/tcp, 1521/tcp, 8080/tcp   oracle11g           
[root@localhost home]# docker start centcommittest 
centcommittest
[root@localhost home]# docker ps
CONTAINER ID        IMAGE                     COMMAND                CREATED             STATUS              PORTS                        NAMES
24e3991b710c        centcommit:v1.0.0         "/bin/bash"            4 hours ago         Up 2 seconds                                     centcommittest      
1ebe9c55d469        centos:latest             "/bin/bash"            23 hours ago        Up 51 minutes                                    centostest          
8cd45d2ffcad        wnameless/oracle-xe-11g   "/bin/sh -c '/usr/sb   10 days ago         Up 4 hours          22/tcp, 1521/tcp, 8080/tcp   oracle11g           

docker stop 終止執行的容器

docker stop id/name
[root@localhost ~]# docker stop dreamy_fermat 
dreamy_fermat

tag       Tag an image into a repository

docker tag [OPTIONS] IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]
docker tag centoscommittest:latest  loneboo/centoscommittest:v1.0.0

 top       Lookup the running processes of a container

[root@localhost home]# docker top centostest 
UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
root                9792                1195                0                   14:59               pts/2               00:00:00            /bin/bash
[root@localhost home]# 


docker unpause   Unpause a paused container 恢復被暫停的容器

docker unpause name/id

docker version    顯示daocker版本資訊
[root@localhost ~]# docker version
Client version: 1.7.1
Client API version: 1.19
Go version (client): go1.4.2
Git commit (client): 786b29d
OS/Arch (client): linux/amd64
Server version: 1.7.1
Server API version: 1.19
Go version (server): go1.4.2
Git commit (server): 786b29d
OS/Arch (server): linux/amd64
    wait      Block until a container stops, then print its exit code


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28282660/viewspace-1794441/,如需轉載,請註明出處,否則將追究法律責任。