Table of contents


名稱

  • container : 像是process的東西,不同之處在於docker可以有多個程式在同一個container裡執行(其實更像unix的jails), container可以是,每個container會會有一個container id,用sudo docker ps就可以看到目前的container list
  • repository : 放image的地方 ex: docker hub
  • image : 可以在container執行的單元,如果docker host上找不到對應的image,就會到docker host上去找

tip

  • docker如果裝在ubuntu上,就要用ubuntu的image,如果裝在cetos上,就要用centos的image
  • image可以用Dockerfile 或 直接用command做,建議是使用Dockerfile
  • 兩個container間可以透過link的機制互相溝通,ex: web container 可以 link 到 db container,就可以抓 db 裡的資料了

指令

Commands:

    attach    Attach 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 from the containers filesystem to the host path
    diff      Inspect changes on a container's filesystem
    events    Get real time events from the server
    export    Stream the contents of a container as a tar archive
    history   Show the history of an image
    images    List images
    import    Create a new filesystem image from the contents of a tarball
    info      Display system-wide information
    inspect   Return low-level information on a container
    kill      Kill a running container
    load      Load an image from a tar archive
    login     Register or Login to the docker registry server
    logs      Fetch the logs of a container
    port      Lookup the public-facing port which is NAT-ed to PRIVATE_PORT
    pause     Pause all processes within a container
    ps        List containers
    pull      Pull an image or a repository from the docker registry server
    push      Push an image or a repository to the docker registry server
    restart   Restart a running container
    rm        Remove one or more containers
    rmi       Remove one or more images
    run       Run a command in a new container
    save      Save an image to a tar archive
    search    Search for an image in the docker index
    start     Start a stopped container
    stop      Stop a running container
    tag       Tag an image into a repository
    top       Lookup the running processes of a container
    unpause   Unpause a paused container
    version   Show the docker version information
    wait      Block until a container stops, then print its exit code

進入ubuntu image的bash中

sudo docker run -t -i ubuntu:14.04 /bin/bash

在進入 ubuntu14.04 為基礎的image,之後所有的指令會在這個image裡下,不用在sudo docker了

  • -t : pseudo-tty
  • -i : 取得container的stdin的互動性連線

列出目前的container

$ sudo docker ps
CONTAINER ID  IMAGE         COMMAND               CREATED        STATUS       PORTS NAMES
1e5535038e28  ubuntu:14.04  /bin/sh -c 'while tr  2 minutes ago  Up 1 minute        insane_babbage

用 logs 顯示container的 standard output

sudo docker logs insane_babbage

insane_babbage 是docker建立時,自動產生container name,但也可以指定成特定的名稱

用stop 停止container

sudo docker stop insane_babbage

連入執行中的container並進入bash

attach一次只能有一個instace,所以如果要連入執行中的container,可用exec

docker exec -t -i image_name bash

docker 系統資訊

可以顯示目前的container,images跟登入的docker hub帳號…資執

$ sudo docker info

Containers: 10
Images: 7
Storage Driver: aufs
 Root Dir: /var/lib/docker/aufs
 Dirs: 27
Execution Driver: native-0.2
Kernel Version: 3.13.0-40-generic
Username: kentchiu
Registry: [https://index.docker.io/v1/]
WARNING: No swap limit support

刪掉無用的images

移掉 <none>的images

sudo docker ps -a -q | xargs -n 1 -I {} sudo docker rm {}
sudo docker rmi $(sudo docker images | grep "^<none>" | awk "{print $3}")

移掉指令的images

sudo docker rmi -f [image ...]

TBC

image

  • centos 上用ubuntu的imgage可行嗎?

    ans: 可,但不管用那個,好像kernel都還是跑執行docker的那個linux的kernel

  • unbuntu 上run不同版本的ubuntu image可行嗎?

    ans: 可,sudo docker run -t -i ubunt:12.04 /bin/bash 這樣就會run 12.04版本的,也可以把12.04這個tag換成13.10或10.04就會執行指定的版本

  • 其他跟os無關的images,是不是可以混著用呢,或者是說有分ubuntu專用的mysql跟cetos專用的mysql嗎?
  • 如果是自已的程式,怎麼弄成image

docker hub

  • 只有私有的一個docker hub夠用嗎?
  • 有辦法自已弄私人的docker repository server嗎?

resource