docker命令

docker logs

docker logs -f -t --since="2017-05-31" --tail=10 container
  • 說明:
    --since : 指定輸出日志開始日期脊阴。
    -f : 查看實(shí)時(shí)日志
    -t : 查看日志產(chǎn)生的時(shí)間戳
    -tail=10 : 查看最后的10條日志蟆湖。
    container : 容器名
docker logs -f --until=2s
  • 說明:
    相對(duì)時(shí)間(relative):2013-01-02T13:23:37
    絕對(duì)時(shí)間(timestamp):42m for 42 minutes
docker logs [OPTIONS] CONTAINER

Options

Name, shorthand Default Description
--details Show extra details provided to logs
--follow , -f Follow log output
--since Show logs since timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m for 42 minutes)
--tail all Number of lines to show from the end of the logs
--timestamps , -t Show timestamps
--until Show logs before a timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m for 42 minutes)

docker history

docker history -q IMAGE
  • 說明:
Name, shorthand Default Description
--format Pretty-print images using a Go template
--human , -H true Print sizes and dates in human readable format
--no-trunc Don’t truncate output
--quiet , -q Only show numeric IDs

truncate 縮短族购、刪節(jié)

docker build

docker build [OPTIONS] PATH | URL | -
  • 說明:
Name, shorthand Default Description
--add-host Add a custom host-to-IP mapping (host:ip)
--build-arg Set build-time variables
--cache-from Images to consider as cache sources
--cgroup-parent Optional parent cgroup for the container
--compress Compress the build context using gzip
--cpu-period Limit the CPU CFS (Completely Fair Scheduler) period
--cpu-quota Limit the CPU CFS (Completely Fair Scheduler) quota
--cpu-shares , -c CPU shares (relative weight)
--cpuset-cpus CPUs in which to allow execution (0-3, 0,1)
--cpuset-mems MEMs in which to allow execution (0-3, 0,1)
--disable-content-trust true Skip image verification
--file , -f Name of the Dockerfile (Default is ‘PATH/Dockerfile’)
--force-rm Always remove intermediate containers
--iidfile Write the image ID to the file
--isolation Container isolation technology
--label Set metadata for an image
--memory , -m Memory limit
--memory-swap Swap limit equal to memory plus swap: ‘-1’ to enable unlimited swap
--network Set the networking mode for the RUN instructions during build
--no-cache Do not use cache when building the image
--platform Set platform if server is multi-platform capable
--progress auto Set type of progress output (auto, plain, tty). Use plain to show container output
--pull Always attempt to pull a newer version of the image
--quiet , -q Suppress the build output and print image ID on success
--rm true Remove intermediate containers after a successful build
--secret Secret file to expose to the build (only if BuildKit enabled): id=mysecret,src=/local/secret
--security-opt Security options
--shm-size Size of /dev/shm
--squash Squash newly built layers into a single new layer
--ssh SSH agent socket or keys to expose to the build (only if BuildKit enabled) (format: default|[=|[,]])
--stream Stream attaches to server to negotiate build context
--tag , -t Name and optionally a tag in the ‘name:tag’ format
--target Set the target build stage to build.
--ulimit Ulimit options

docker run

$ docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]
  • 說明:
    -a stdin: 指定標(biāo)準(zhǔn)輸入輸出內(nèi)容類型局荚,可選 STDIN/STDOUT/STDERR 三項(xiàng)蕉世;
    -i: 以交互模式運(yùn)行容器婿崭,通常與 -t 同時(shí)使用-it;
    -t: 為容器重新分配一個(gè)偽輸入終端躺枕,通常與 -i 同時(shí)使用-it服猪;
    -P: 隨機(jī)端口映射,容器內(nèi)部端口隨機(jī)映射到主機(jī)的高端口拐云;
    -p: 指定端口映射罢猪,格式為:主機(jī)(宿主)端口:容器端口;
    --name="nginx-lb": 為容器指定一個(gè)名稱叉瘩;
    --dns 8.8.8.8: 指定容器使用的DNS服務(wù)器膳帕,默認(rèn)和宿主一致;
    --dns-search example.com: 指定容器DNS搜索域名薇缅,默認(rèn)和宿主一致危彩;
    -h "mars": 指定容器的hostname;
    -e username="ritchie": 設(shè)置環(huán)境變量泳桦;
    --env-file=[]: 從指定文件讀入環(huán)境變量汤徽;
    --cpuset="0-2" or --cpuset="0,1,2": 綁定容器到指定CPU運(yùn)行;
    -m :設(shè)置容器使用內(nèi)存最大值灸撰;
    --net="bridge": 指定容器的網(wǎng)絡(luò)連接類型谒府,支持 bridge/host/none/container: 四種類型;
    --link=[]: 添加鏈接到另一個(gè)容器浮毯;
    --expose=[]: 開放一個(gè)端口或一組端口完疫;
$ docker run -d -p 80:80 my_image service nginx start
  • 說明:
    后臺(tái)創(chuàng)建容器,返回容器ID亲轨,并在容器內(nèi)啟動(dòng)nginx
$ docker run -a stdin -a stdout -it ubuntu /bin/bash
  • 說明:
    -a stdin: 指定標(biāo)準(zhǔn)輸入輸出內(nèi)容類型趋惨,可選 STDIN/STDOUT/STDERR 三項(xiàng);
$ docker run alpine@sha256:9cacb71397b640eca97488cf08582ae4e4068513101088e9f96c9814bfda95e0 date
  • 說明:
    Image[@digest]

PID settings (--pid)

--pid=""  : Set the PID (Process) Namespace mode for the container,
             'container:<name|id>': joins another container's PID namespace
             'host': use the host's PID namespace inside the container
  • 說明:
    -- 默認(rèn)情況下惦蚊,所有容器都啟用了PID名稱空間器虾。
    -- PID命名空間提供進(jìn)程分離讯嫂。PID命名空間刪除了系統(tǒng)進(jìn)程的視圖,并允許包括PID 1在內(nèi)的進(jìn)程id被重用兆沙。
    -- 在某些情況下欧芽,您希望容器共享主機(jī)的進(jìn)程名稱空間,基本上允許容器內(nèi)的進(jìn)程查看系統(tǒng)上的所有進(jìn)程葛圃。

Example: run htop inside a container

創(chuàng)建Dockerfile:

FROM alpine:latest
RUN apk add --update htop && rm -rf /var/cache/apk/*
CMD ["htop"]

依據(jù)dockerfile創(chuàng)建鏡像myhtop:

$ docker build -t myhtop .

Use the following command to run htop inside a container:

$ docker run -it --rm --pid=host myhtop

加入另一個(gè)容器的pid名稱空間可用于調(diào)試該容器千扔。

docker run Usage

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

Options

Name, shorthand Default Description
--add-host Add a custom host-to-IP mapping (host:ip)
--attach , -a Attach to STDIN, STDOUT or STDERR
--blkio-weight Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0)
--blkio-weight-device Block IO weight (relative device 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-count CPU count (Windows only)
--cpu-percent CPU percent (Windows only)
--cpu-period Limit CPU CFS (Completely Fair Scheduler) period
--cpu-quota Limit CPU CFS (Completely Fair Scheduler) quota
--cpu-rt-period Limit CPU real-time period in microseconds
--cpu-rt-runtime Limit CPU real-time runtime in microseconds
--cpu-shares , -c CPU shares (relative weight)
--cpus Number of CPUs
--cpuset-cpus CPUs in which to allow execution (0-3, 0,1)
--cpuset-mems MEMs in which to allow execution (0-3, 0,1)
--detach , -d Run container in background and print container ID
--detach-keys Override the key sequence for detaching a container
--device Add a host device to the container
--device-cgroup-rule Add a rule to the cgroup allowed devices list
--device-read-bps Limit read rate (bytes per second) from a device
--device-read-iops Limit read rate (IO per second) from a device
--device-write-bps Limit write rate (bytes per second) to a device
--device-write-iops Limit write rate (IO per second) to a device
--disable-content-trust true Skip image verification
--dns Set custom DNS servers
--dns-opt Set DNS options
--dns-option Set DNS options
--dns-search Set custom DNS search domains
--entrypoint Overwrite the default ENTRYPOINT of the image
--env , -e Set environment variables
--env-file Read in a file of environment variables
--expose Expose a port or a range of ports
--group-add Add additional groups to join
--health-cmd Command to run to check health
--health-interval Time between running the check (ms|s|m|h) (default 0s)
--health-retries Consecutive failures needed to report unhealthy
--health-start-period Start period for the container to initialize before starting health-retries countdown (ms|s|m|h) (default 0s)
--health-timeout Maximum time to allow one check to run (ms|s|m|h) (default 0s)
--help Print usage
--hostname , -h Container host name
--init Run an init inside the container that forwards signals and reaps processes
--interactive , -i Keep STDIN open even if not attached
--io-maxbandwidth Maximum IO bandwidth limit for the system drive (Windows only)
--io-maxiops Maximum IOps limit for the system drive (Windows only)
--ip IPv4 address (e.g., 172.30.100.104)
--ip6 IPv6 address (e.g., 2001:db8::33)
--ipc IPC mode to use
--isolation Container isolation technology
--kernel-memory Kernel memory limit
--label , -l Set meta data on a container
--label-file Read in a line delimited file of labels
--link Add link to another container
--link-local-ip Container IPv4/IPv6 link-local addresses
--log-driver Logging driver for the container
--log-opt Log driver options
--mac-address Container MAC address (e.g., 92:d0:c6:0a:29:33)
--memory , -m Memory limit
--memory-reservation Memory soft limit
--memory-swap Swap limit equal to memory plus swap: ‘-1’ to enable unlimited swap
--memory-swappiness -1 Tune container memory swappiness (0 to 100)
--mount Attach a filesystem mount to the container
--name Assign a name to the container
--net Connect a container to a network
--net-alias Add network-scoped alias for the container
--network Connect a container to a network
--network-alias Add network-scoped alias for the container
--no-healthcheck Disable any container-specified HEALTHCHECK
--oom-kill-disable Disable OOM Killer
--oom-score-adj Tune host’s OOM preferences (-1000 to 1000)
--pid PID namespace to use
--pids-limit Tune container pids limit (set -1 for unlimited)
--platform Set platform if server is multi-platform capable
--privileged Give extended privileges to this container
--publish , -p Publish a container’s port(s) to the host
--publish-all , -P Publish all exposed ports to random ports
--read-only Mount the container’s root filesystem as read only
--restart no Restart policy to apply when a container exits
--rm Automatically remove the container when it exits
--runtime Runtime to use for this container
--security-opt Security Options
--shm-size Size of /dev/shm
--sig-proxy true Proxy received signals to the process
--stop-signal SIGTERM Signal to stop a container
--stop-timeout Timeout (in seconds) to stop a container
--storage-opt Storage driver options for the container
--sysctl Sysctl options
--tmpfs Mount a tmpfs directory
--tty , -t Allocate a pseudo-TTY
--ulimit Ulimit options
--user , -u Username or UID (format: <name|uid>[:<group|gid>])
--userns User namespace to use
--uts UTS namespace to use
--volume , -v Bind mount a volume
--volume-driver Optional volume driver for the container
--volumes-from Mount volumes from the specified container(s)
--workdir , -w Working directory inside the container
$ docker  run -w /path/to/dir/ -i -t  ubuntu pwd
  • 說明
    The -w lets the command being executed inside directory given, here /path/to/dir/. If the path does not exist it is created inside the container.

docker exec Usage

docker exec [OPTIONS] CONTAINER COMMAND [ARG...]

  • 說明:
Name, shorthand Default Description
--detach , -d Detached mode: run command in the background
--detach-keys Override the key sequence for detaching a container
--env , -e Set environment variables
--interactive , -i Keep STDIN open even if not attached
--privileged Give extended privileges to the command
--tty , -t Allocate a pseudo-TTY
--user , -u Username or UID (format: <name|uid>[:<group|gid>])
--workdir , -w Working directory inside the container
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市库正,隨后出現(xiàn)的幾起案子曲楚,更是在濱河造成了極大的恐慌,老刑警劉巖褥符,帶你破解...
    沈念sama閱讀 219,427評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件龙誊,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡喷楣,警方通過查閱死者的電腦和手機(jī)趟大,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,551評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來铣焊,“玉大人逊朽,你說我怎么就攤上這事∏粒” “怎么了叽讳?”我有些...
    開封第一講書人閱讀 165,747評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)熊昌。 經(jīng)常有香客問我绽榛,道長(zhǎng),這世上最難降的妖魔是什么婿屹? 我笑而不...
    開封第一講書人閱讀 58,939評(píng)論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮推溃,結(jié)果婚禮上昂利,老公的妹妹穿的比我還像新娘。我一直安慰自己铁坎,他們只是感情好蜂奸,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,955評(píng)論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著硬萍,像睡著了一般扩所。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上朴乖,一...
    開封第一講書人閱讀 51,737評(píng)論 1 305
  • 那天祖屏,我揣著相機(jī)與錄音助赞,去河邊找鬼。 笑死袁勺,一個(gè)胖子當(dāng)著我的面吹牛雹食,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播期丰,決...
    沈念sama閱讀 40,448評(píng)論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼群叶,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來了钝荡?” 一聲冷哼從身側(cè)響起街立,我...
    開封第一講書人閱讀 39,352評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎埠通,沒想到半個(gè)月后赎离,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,834評(píng)論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡植阴,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,992評(píng)論 3 338
  • 正文 我和宋清朗相戀三年蟹瘾,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片掠手。...
    茶點(diǎn)故事閱讀 40,133評(píng)論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡憾朴,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出喷鸽,到底是詐尸還是另有隱情众雷,我是刑警寧澤,帶...
    沈念sama閱讀 35,815評(píng)論 5 346
  • 正文 年R本政府宣布做祝,位于F島的核電站砾省,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏混槐。R本人自食惡果不足惜编兄,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,477評(píng)論 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望声登。 院中可真熱鬧狠鸳,春花似錦、人聲如沸悯嗓。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,022評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽脯厨。三九已至铅祸,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間合武,已是汗流浹背临梗。 一陣腳步聲響...
    開封第一講書人閱讀 33,147評(píng)論 1 272
  • 我被黑心中介騙來泰國(guó)打工涡扼, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人夜焦。 一個(gè)月前我還...
    沈念sama閱讀 48,398評(píng)論 3 373
  • 正文 我出身青樓壳澳,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親茫经。 傳聞我的和親對(duì)象是個(gè)殘疾皇子巷波,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,077評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容

  • 額外補(bǔ)充 查看容器運(yùn)行狀態(tài) 進(jìn)入容器內(nèi)進(jìn)行命令行操作 在容器mynginx中開啟一個(gè)交互模式的終端 容器生命周期管...
    tianmac閱讀 4,530評(píng)論 1 2
  • Docker命令分類 容器生命周期管理 容器操作 容器rootfs命令 鏡像倉庫 本地鏡像管理 版本信息 Dock...
    garyond閱讀 2,772評(píng)論 0 4
  • docker命令集容器生命周期管理 容器操作 容器文件系統(tǒng)操作 鏡像倉庫操作 鏡像管理 集群管理 其他命令 命令參...
    yichen_china閱讀 376評(píng)論 0 0
  • Docker學(xué)習(xí)總結(jié)之Run命令介紹 - vikings`s blog - 博客園http://www.cnblo...
    葡萄喃喃囈語閱讀 1,199評(píng)論 0 1
  • 一、Docker 簡(jiǎn)介 Docker 兩個(gè)主要部件:Docker: 開源的容器虛擬化平臺(tái)Docker Hub: 用...
    R_X閱讀 4,389評(píng)論 0 27