Basic Commands

docker search [key-workd]

透過關鍵字搜尋docker hub所提供的docker image。

docker@boot2docker:~$ docker search registry
NAME                                    DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
registry                                Containerized docker registry                   164       [OK]
samalba/docker-registry                                                                 31                   [OK]
atcol/docker-registry-ui                A web UI for easy private/local Docker Reg...   25                   [OK]
fedora/registry                                                                         18                   [OK]
konradkleine/docker-registry-frontend   a pure web-based solution for browsing and...   9                    [OK]
deis/registry                           Docker image registry for the Deis open so...   7
...

docker images

搜尋local已經存在的docker image,已經存在的image在執行時候會直接可以執行,不用再經過下載的動作喔。

docker@boot2docker:~$ docker images
REPOSITORY                                       TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
registry.arecord.us:5000/micloud-oauth-service   latest              0f8d5478ff44        4 days ago          513.3 MB
ubuntu14-erlang17                                latest              f0dec4429575        4 weeks ago         1.647 GB
registry.arecord.us:5000/ubuntu14-erlang17       latest              3ac9fe08539b        4 weeks ago         1.647 GB
<none>                                           <none>              5f09d89f9345        4 weeks ago         1.647 GB
<none>                                           <none>              a6532be1c013        4 weeks ago         1.647 GB
...

docker pull [image-id]

當找到想要使用的image時候。可以透過docker pull將image下載到本地端,供後續使用。

docker@boot2docker:~$ docker pull centos
Pulling repository centos
eeed74b237f9: Download complete
510cf09a7986: Download complete
186bcdab8163: Download complete
8efe422e6104: Download complete
c36ca560b9bf: Download complete
bac0c97c3010: Download complete
511136ea3c5a: Download complete
5b12ef8fd570: Download complete
docker@boot2docker:~$

docker history [image-id]

docker@boot2docker:~$ docker history ubuntu14-erlang17
IMAGE               CREATED             CREATED BY                                      SIZE
f0dec4429575        4 weeks ago         bash                                            1.421 GB
c4ff7513909d        5 months ago        /bin/sh -c #(nop) CMD [/bin/bash]               0 B
cc58e55aa5a5        5 months ago        /bin/sh -c apt-get update && apt-get dist-upg   32.67 MB
0ea0d582fd90        5 months ago        /bin/sh -c sed -i 's/^#\s*\(deb.*universe\)$/   1.895 kB
d92c3c92fa73        5 months ago        /bin/sh -c rm -rf /var/lib/apt/lists/*          0 B
9942dd43ff21        5 months ago        /bin/sh -c echo '#!/bin/sh' > /usr/sbin/polic   194.5 kB
1c9383292a8f        5 months ago        /bin/sh -c #(nop) ADD file:c1472c26527df28498   192.5 MB
511136ea3c5a        19 months ago                                                       0 B

docker run [options] [image] [command]

基本啟動指令

啟動一台centos instance,並且切入bash模式

docker run -it centos bash
  • -i: interactive mode, 讓操作者擁有互動模式
  • -t: terminal, 讓操作者可以使用終端機操作intance

Daemon模式

Docker除了支援互動模式外,也可以直接在設計好的docker中,以daemon方式來執行daemon mode...

dcoker -d -p 5984:5984 -v ~/couchdata:/var/lib/couchdb fedora/couchdb
  • -d: daemon mode, 需要搭配帶入的指令或是dockerfile中的CMD或是ENTRYPOINT來啟動intsance的動作
  • -p [external-port]:[internal-port]: 聯繫內部與外部網路的port number
  • -p [external-port]:[internal-port]/udp: 使用udp port
  • -v [external-folder-path]:[external-folder-path]: 掛載執行主機的目錄位置給instance使用

導出standard output

Docker的執行中,可以透過"-a"參數來將stdout, stderr導出到執行視窗...

$ docker run -d -v /home/simonsu/data:/data -a stdout -a stderr\
>   peihsinsu/apache2 \
>   bash -c "cd /data && ab -c 50 -n 50 -g out.dat http://104.155.231.150/ && gnuplot plot.p"
68de4f0f850858c8426b348818e72adadad5c016178f6851fb5eb7fc04d5c6f1

執行當中,系統將會stdout, stderr導出到視窗中。

PS: Interactive mode時候,請不要使用"-a"參數,似乎會把操作卡住...

results matching ""

    No results matching ""