Docker run 命令詳解

學習Docker一段時間啦殿漠,上周在和同事討論時發(fā)現(xiàn)自己對run命令還存在不了解的地方亥鬓,因此特意整理一遍傻寂,目的:加強記憶息尺。 內容來源于官網(wǎng)和網(wǎng)上其他牛人整理。

語法

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

使用 docker run --help 查看的詳細如下:

# docker run --help
Usage:  docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Run a command in a new container
Options:
      --add-host value              Add a custom host-to-IP mapping (host:ip) (default [])
     # 給即將啟動的容器在/etc/hosts中添加host:ip疾掰,在容器中可用host訪問
     例子:docker run -ti --add-host winxin:192.168.220.125 80d2 /bin/bash
  -a, --attach value                Attach to STDIN, STDOUT or STDERR (default [])
     # stdout(Standardoutput)標準輸出搂誉、stdin(Standardinput)標準輸入、stderr(Standarderror)標準錯誤
      --blkio-weight value          Block IO (relative weight), between 10 and 1000
    #容器使用的IO控制静檬,存在疑問是控制讀和寫炭懊?[xiaosun26](http://my.csdn.net/xiaosun26)做了個測試表明只對讀有控制,對寫是沒有影響的拂檩。---待測試侮腹。
      --blkio-weight-device value   Block IO weight (relative device weight) (default [])
      --cap-add value               Add Linux capabilities (default [])
     #如 --cap-add=NET_ADMIN 可修改網(wǎng)絡接口數(shù)據(jù),或者ALL則所有權限稻励。
      --cap-drop value              Drop Linux capabilities (default [])
     #刪除掉某些權限 
      --cgroup-parent string        Optional parent cgroup for the container
      --cidfile string              Write the container ID to the file
      --cpu-percent int             CPU percent (Windows only)
      --cpu-period int              Limit CPU CFS (Completely Fair Scheduler) period
      --cpu-quota int               Limit CPU CFS (Completely Fair Scheduler) quota
  -c, --cpu-shares int              CPU shares (relative weight)
      #設置成0則100%使用CPU
      --cpuset-cpus string          CPUs in which to allow execution (0-3, 0,1)
      --cpuset-mems string          MEMs in which to allow execution (0-3, 0,1)
  -d, --detach                      Run container in background and print container ID
      #常用父阻,容器后臺運行,并打印容器id
      --detach-keys string          Override the key sequence for detaching a container
      --device value                Add a host device to the container (default [])
      #--device=/dev/sda:/dev/xvdc 將設備映射到容器中
      --device-read-bps value       Limit read rate (bytes per second) from a device (default [])
      --device-read-iops value      Limit read rate (IO per second) from a device (default [])
      --device-write-bps value      Limit write rate (bytes per second) to a device (default [])
      --device-write-iops value     Limit write rate (IO per second) to a device (default [])
      --disable-content-trust       Skip image verification (default true)
      --dns value                   Set custom DNS servers (default [])
      --dns-opt value               Set DNS options (default [])
      --dns-search value            Set custom DNS search domains (default [])
      --entrypoint string           Overwrite the default ENTRYPOINT of the image
     #覆蓋image中的entrypoint
  -e, --env value                   Set environment variables (default [])
     #設置換變量 -e "MYSQL_PORT=3306"
      --env-file value              Read in a file of environment variables (default [])
      --expose value                Expose a port or a range of ports (default [])
      --group-add value             Add additional groups to join (default [])
      --health-cmd string           Command to run to check health
      --health-interval duration    Time between running the check
      --health-retries int          Consecutive failures needed to report unhealthy
      --health-timeout duration     Maximum time to allow one check to run
      --help                        Print usage
  -h, --hostname string             Container host name
      #常用望抽,如不設置成每次Container的hostname都是不一樣的加矛。
  -i, --interactive                 Keep STDIN open even if not attached
     #常用,交互模式
      --io-maxbandwidth string      Maximum IO bandwidth limit for the system drive (Windows only)
      --io-maxiops uint             Maximum IOps limit for the system drive (Windows only)
      --ip string                   Container IPv4 address (e.g. 172.30.100.104)
      #常用煤篙,如不設置每次Container的IP都是變動
      --ip6 string                  Container IPv6 address (e.g. 2001:db8::33)
      --ipc string                  IPC namespace to use
      --isolation string            Container isolation technology
      --kernel-memory string        Kernel memory limit
  -l, --label value                 Set meta data on a container (default [])
      --label-file value            Read in a line delimited file of labels (default [])
      --link value                  Add link to another container (default [])
      #常用斟览,link另一個容器關聯(lián)到當前容器中
      --link-local-ip value         Container IPv4/IPv6 link-local addresses (default [])
      --log-driver string           Logging driver for the container
      --log-opt value               Log driver options (default [])
      --mac-address string          Container MAC address (e.g. 92:d0:c6:0a:29:33)
  -m, --memory string               Memory limit
       #設置內存
      --memory-reservation string   Memory soft limit
      --memory-swap string          Swap limit equal to memory plus swap: '-1' to enable unlimited swap
      --memory-swappiness int       Tune container memory swappiness (0 to 100) (default -1)
      --name string                 Assign a name to the container
       #設置容器的名稱
      --network string              Connect a container to a network (default "default")
      --network-alias value         Add network-scoped alias for the container (default [])
      --no-healthcheck              Disable any container-specified HEALTHCHECK
      --oom-kill-disable            Disable OOM Killer
      --oom-score-adj int           Tune host's OOM preferences (-1000 to 1000)
      --pid string                  PID namespace to use
      --pids-limit int              Tune container pids limit (set -1 for unlimited)
      --privileged                  Give extended privileges to this container
      #一個十分強悍的命令,不設置時辑奈,容器里無法在啟動容器苛茂,沒有使用宿主機設備的權限
  -p, --publish value               Publish a container's port(s) to the host (default [])
  -P, --publish-all                 Publish all exposed ports to random ports
      --read-only                   Mount the container's root filesystem as read only
      --restart string              Restart policy to apply when a container exits (default "no")
      --rm                          Automatically remove the container when it exits
       #當容器存在時自動刪除已烤,rm和-d命令是沖突的
      --runtime string              Runtime to use for this container
      --security-opt value          Security Options (default [])
      --shm-size string             Size of /dev/shm, default value is 64MB
      --sig-proxy                   Proxy received signals to the process (default true)
      --stop-signal string          Signal to stop a container, SIGTERM by default (default "SIGTERM")
      --storage-opt value           Storage driver options for the container (default [])
      --sysctl value                Sysctl options (default map[])
      --tmpfs value                 Mount a tmpfs directory (default [])
  -t, --tty                         Allocate a pseudo-TTY
      --ulimit value                Ulimit options (default [])
  -u, --user string                 Username or UID (format: <name|uid>[:<group|gid>])
      --userns string               User namespace to use
      --uts string                  UTS namespace to use
  -v, --volume value                Bind mount a volume (default [])
    #常用,掛載volume到容器中
      --volume-driver string        Optional volume driver for the container
      --volumes-from value          Mount volumes from the specified container(s) (default [])
  -w, --workdir string              Working directory inside the container
    #設置容器里work目錄
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末味悄,一起剝皮案震驚了整個濱河市草戈,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌侍瑟,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,858評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件丙猬,死亡現(xiàn)場離奇詭異涨颜,居然都是意外死亡,警方通過查閱死者的電腦和手機茧球,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,372評論 3 395
  • 文/潘曉璐 我一進店門庭瑰,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人抢埋,你說我怎么就攤上這事弹灭。” “怎么了揪垄?”我有些...
    開封第一講書人閱讀 165,282評論 0 356
  • 文/不壞的土叔 我叫張陵穷吮,是天一觀的道長饥努。 經(jīng)常有香客問我,道長驾诈,這世上最難降的妖魔是什么乍迄? 我笑而不...
    開封第一講書人閱讀 58,842評論 1 295
  • 正文 為了忘掉前任士败,我火速辦了婚禮,結果婚禮上生蚁,老公的妹妹穿的比我還像新娘戏自。我一直安慰自己,他們只是感情好擅笔,可當我...
    茶點故事閱讀 67,857評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著狞洋,像睡著了一般绿店。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上假勿,一...
    開封第一講書人閱讀 51,679評論 1 305
  • 那天转培,我揣著相機與錄音,去河邊找鬼惨寿。 笑死删窒,一個胖子當著我的面吹牛,可吹牛的內容都是我干的缸废。 我是一名探鬼主播驶社,決...
    沈念sama閱讀 40,406評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼亡电,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了份乒?” 一聲冷哼從身側響起或辖,我...
    開封第一講書人閱讀 39,311評論 0 276
  • 序言:老撾萬榮一對情侶失蹤颂暇,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后耳鸯,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體膀曾,經(jīng)...
    沈念sama閱讀 45,767評論 1 315
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 37,945評論 3 336
  • 正文 我和宋清朗相戀三年斩狱,在試婚紗的時候發(fā)現(xiàn)自己被綠了卷拘。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,090評論 1 350
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖乍赫,靈堂內的尸體忽然破棺而出陆蟆,到底是詐尸還是另有隱情,我是刑警寧澤叠殷,帶...
    沈念sama閱讀 35,785評論 5 346
  • 正文 年R本政府宣布林束,位于F島的核電站,受9級特大地震影響缕题,放射性物質發(fā)生泄漏。R本人自食惡果不足惜烟零,卻給世界環(huán)境...
    茶點故事閱讀 41,420評論 3 331
  • 文/蒙蒙 一锨阿、第九天 我趴在偏房一處隱蔽的房頂上張望记罚。 院中可真熱鬧,春花似錦毫胜、人聲如沸诬辈。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,988評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽痪欲。三九已至,卻和暖如春栗柒,著一層夾襖步出監(jiān)牢的瞬間知举,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,101評論 1 271
  • 我被黑心中介騙來泰國打工逛钻, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留曙痘,地道東北人立肘。 一個月前我還...
    沈念sama閱讀 48,298評論 3 372
  • 正文 我出身青樓,卻偏偏與公主長得像惩嘉,于是被迫代替她去往敵國和親踢故。 傳聞我的和親對象是個殘疾皇子殿较,可洞房花燭夜當晚...
    茶點故事閱讀 45,033評論 2 355

推薦閱讀更多精彩內容