docker-compose命令介绍和使用【官方英文文档翻译】【附加案例】
夫陶公清風(fēng)千古,余又何人,敢稱(chēng)庶幾
文章目錄
- 簡(jiǎn)介
- 命令
- docker-compose ps
- docker-compose up
- docker-compose down
- docker-compose logs
- docker-compose build
- docker-compose port
- docker-compose rm
- docker-compose restart
- docker-compose start
- docker-compose config
- docker-compose stop
- docker-compose kill
簡(jiǎn)介
- :表示縮寫(xiě)
–:表示全稱(chēng)
命令
docker-compose ps
Lists containers.
顯示所有容器
原文:
Usage: ps [options] [SERVICE...]Options:-q, --quiet Only display IDs--services Display services--filter KEY=VAL Filter services by a property-a, --all Show all stopped containers (including those created by the run command)翻譯:
使用方法:ps [選項(xiàng)] [服務(wù)…]選項(xiàng):-q, --quiet 只顯示所有容器的ID--services 顯示所有服務(wù)--filter KEY=VAL 通過(guò)屬性篩選服務(wù)-a, --all 顯示所有已停止的容器(包括由run命令創(chuàng)建的容器)案例:
事先運(yùn)行容器 :
[root@VM-0-11-centos tomcat]# ls
docker-compose.yml
[root@VM-0-11-centos tomcat]# docker-compose up -d
–filter KEY=VAL
-a,–all
docker-compose up
Builds, (re)creates, starts, and attaches to containers for a service.
構(gòu)建、(重新)創(chuàng)建、啟動(dòng)和附加到服務(wù)容器上。
原文:
Usage: up [options] [--scale SERVICE=NUM...] [SERVICE...]Options:-d, --detach Detached mode: Run containers in the background,print new container names. Incompatible with--abort-on-container-exit.--no-color Produce monochrome output.--quiet-pull Pull without printing progress information--no-deps Don't start linked services.--force-recreate Recreate containers even if their configurationand image haven't changed.--always-recreate-deps Recreate dependent containers.Incompatible with --no-recreate.--no-recreate If containers already exist, don't recreatethem. Incompatible with --force-recreate and --renew-anon-volumes.--no-build Don't build an image, even if it's missing.--no-start Don't start the services after creating them.--build Build images before starting containers.--abort-on-container-exit Stops all containers if any container wasstopped. Incompatible with --detach.--attach-dependencies Attach to dependent containers.-t, --timeout TIMEOUT Use this timeout in seconds for containershutdown when attached or when containers arealready running. (default: 10)-V, --renew-anon-volumes Recreate anonymous volumes instead of retrievingdata from the previous containers.--remove-orphans Remove containers for services not definedin the Compose file.--exit-code-from SERVICE Return the exit code of the selected servicecontainer. Implies --abort-on-container-exit.--scale SERVICE=NUM Scale SERVICE to NUM instances. Overrides the`scale` setting in the Compose file if present.翻譯:
使用方法: up [選項(xiàng)] [--scale SERVICE=NUM...] [SERVICE...]選項(xiàng):-d, --detach 附加模式:在后臺(tái)運(yùn)行容器,打印新的容器名稱(chēng)。不兼容——abort-on-container-exit。--no-color 以單色輸出--quiet-pull 拉取而不打印進(jìn)度信息--no-deps 不啟動(dòng)鏈接服務(wù)--force-recreate 即使容器的配置和鏡像沒(méi)有改變, 容器也要重新被創(chuàng)建--always-recreate-deps 重新創(chuàng)建容器的依賴(lài),不兼容——no-recreate--no-recreate 如果容器已經(jīng)存在,不要重新創(chuàng)建它們。-force-和-renew-anon-volumes不兼容。--no-build 不要構(gòu)建一個(gè)鏡像,即使它缺失--no-start 創(chuàng)建服務(wù)后不要啟動(dòng)它們--build 在啟動(dòng)容器之前構(gòu)建鏡像--abort-on-container-exit 如果任何容器被停止,則停止所有容器。與--detach不兼容--attach-dependencies 附加到依賴(lài)容器-t, --timeout TIMEOUT 當(dāng)附加容器或容器已經(jīng)在運(yùn)行時(shí),使用此超時(shí)(以秒為單位)用于關(guān)閉容器。(默認(rèn)值:10)-V, --renew-anon-volumes 重新創(chuàng)建匿名數(shù)據(jù)卷,而不是從以前的容器檢索數(shù)據(jù)--remove-orphans 刪除Compose文件中未定義的服務(wù)容器。--exit-code-from SERVICE 返回所選服務(wù)容器的退出代碼。意味著——abort-on-container-exit。--scale SERVICE=NUM 將服務(wù)擴(kuò)展到NUM實(shí)例。如果存在,將覆蓋Compose文件中的“scale”設(shè)置。案例:
docker-compose down
Stops containers and removes containers, networks, volumes, and images created by up.
停止容器并刪除up創(chuàng)建的容器、網(wǎng)絡(luò)、數(shù)據(jù)卷和鏡像。
原文:
Usage: down [options]Options:--rmi type Remove images. Type must be one of:'all': Remove all images used by any service.'local': Remove only images that don't have acustom tag set by the `image` field.-v, --volumes Remove named volumes declared in the `volumes`section of the Compose file and anonymous volumesattached to containers.--remove-orphans Remove containers for services not defined in theCompose file-t, --timeout TIMEOUT Specify a shutdown timeout in seconds.(default: 10)翻譯:
用法:down[選項(xiàng)] 選項(xiàng):--rmi type 刪除鏡像。類(lèi)型必須是以下之一:'all':刪除任何服務(wù)使用的所有鏡像。'local':只刪除沒(méi)有' image '字段設(shè)置的自定義標(biāo)簽的圖像。-v, --volumes 刪除在Compose文件的' volumes '部分聲明的命名卷和附加到容器上的匿名卷。--remove-orphans 刪除在Compose文件中未定義的服務(wù)容器-t, --timeout TIMEOUT 指定關(guān)機(jī)超時(shí)時(shí)間(以秒為單位)。( 默認(rèn)值:10)案例:
docker-compose logs
Displays log output from services.
顯示服務(wù)的日志輸出。
原文:
Usage: logs [options] [SERVICE...]Options:--no-color Produce monochrome output.-f, --follow Follow log output.-t, --timestamps Show timestamps.--tail="all" Number of lines to show from the end of the logsfor each container.翻譯:
Usage: logs [options] [SERVICE...]Options:--no-color 產(chǎn)生單色輸出。-f, --follow 遵循日志輸出-t, --timestamps 顯示時(shí)間戳。--tail="all" 從每個(gè)容器的日志末尾開(kāi)始顯示行數(shù)。案例:
docker-compose build
Services are built once and then tagged, by default as project_service. For example, composetest_db. If the Compose file specifies an image name, the image is tagged with that name, substituting any variables beforehand. See variable substitution.
If you change a service’s Dockerfile or the contents of its build directory, run docker-compose build to rebuild it.
服務(wù)只構(gòu)建一次,然后被標(biāo)記,默認(rèn)為project_service。例如,composetest_db。如果Compose文件指定了一個(gè)鏡像名稱(chēng),則該鏡像將使用該名稱(chēng)進(jìn)行標(biāo)記,并預(yù)先替換任何變量。看到變量替換。
如果你改變了一個(gè)服務(wù)的Dockerfile或者它的構(gòu)建目錄的內(nèi)容,運(yùn)行docker-compose build來(lái)重建它。
原文:
Usage: build [options] [--build-arg key=val...] [SERVICE...]Options:--build-arg key=val Set build-time variables for services.--compress Compress the build context using gzip.--force-rm Always remove intermediate containers.-m, --memory MEM Set memory limit for the build container.--no-cache Do not use cache when building the image.--no-rm Do not remove intermediate containers after a successful build.--parallel Build images in parallel.--progress string Set type of progress output (`auto`, `plain`, `tty`).--pull Always attempt to pull a newer version of the image.-q, --quiet Don't print anything to `STDOUT`.翻譯:
使用方法: build [選項(xiàng)] [--build-arg key=val...] [SERVICE...]選項(xiàng):--build-arg key=val 為服務(wù)設(shè)置構(gòu)建時(shí)變量。--compress 使用gzip壓縮構(gòu)建上下文。--force-rm 始終移除中間容器-m, --memory MEM 為構(gòu)建容器設(shè)置內(nèi)存限制。--no-cache 在構(gòu)建鏡像時(shí)不要使用緩存。--no-rm 在成功構(gòu)建之后,不要?jiǎng)h除中間容器。--parallel 并行構(gòu)建映像。--progress string 設(shè)置進(jìn)度輸出類(lèi)型(' auto ', ' plain ', ' tty ')。--pull 總是嘗試?yán)鲆粋€(gè)新版本的鏡像。-q, --quiet 不要打印任何東西到' STDOUT '。案例:
List item
List item
List item
List item
List item
docker-compose port
Prints the public port for a port binding.
打印端口綁定的公共端口。
原文:
Usage: port [options] SERVICE PRIVATE_PORTOptions:--protocol=proto tcp or udp [default: tcp]--index=index index of the container if there are multipleinstances of a service [default: 1]翻譯:
使用方法:port [選項(xiàng)] SERVICE PRIVATE_PORT選項(xiàng):--protocol=proto tcp或udp[默認(rèn)值:tcp]--index=index 如果服務(wù)有多個(gè)實(shí)例,則為容器索引[默認(rèn)值:1]案例:
無(wú)選項(xiàng)
–protocol=proto
–index=index
docker-compose rm
Removes stopped service containers.
移除停止服務(wù)容器。
原文:
Usage: rm [options] [SERVICE...]Options:-f, --force Don't ask to confirm removal-s, --stop Stop the containers, if required, before removing-v Remove any anonymous volumes attached to containers-a, --all Deprecated - no effect.翻譯:
Usage: rm [options] [SERVICE...]Options:-f, --force 強(qiáng)制刪除-s, --stop 如果需要,在刪除容器之前,停止容器-v 刪除任何附加到容器上的匿名數(shù)據(jù)卷-a, --all 棄用 - no effect.案例:
-f, --force
-s, --stop
-v
-a, --all
docker-compose restart
Restarts all stopped and running services.
重啟所有已停止和正在運(yùn)行的服務(wù)。
原文:
Usage: restart [options] [SERVICE...]Options:-t, --timeout TIMEOUT Specify a shutdown timeout in seconds.(default: 10)翻譯:
使用方法: restart [選項(xiàng)] [SERVICE...]選項(xiàng):-t, --timeout TIMEOUT 指定關(guān)機(jī)超時(shí)時(shí)間(以秒為單位)。(默認(rèn)值:10)案例:
docker-compose start
Starts existing containers for a service.
啟動(dòng)已經(jīng)存在容器的服務(wù)。
原文:
Usage: start [SERVICE...]翻譯:
使用方法: start [SERVICE...]案例:
List item
List item
List item
List item
List item
docker-compose config
Validate and view the Compose file.
驗(yàn)證并查看Compose文件。
原文:
Usage: config [options]Options:--resolve-image-digests Pin image tags to digests.--no-interpolate Don't interpolate environment variables.-q, --quiet Only validate the configuration, don't printanything.--services Print the service names, one per line.--volumes Print the volume names, one per line.--hash="*" Print the service config hash, one per line.Set "service1,service2" for a list of specified servicesor use the wildcard symbol to display all services.翻譯:
Usage: config [options]Options:--resolve-image-digests Pin鏡像標(biāo)簽到摘要。--no-interpolate 不插入環(huán)境變量。-q, --quiet 只驗(yàn)證配置,不打印任何東西。--services 打印服務(wù)名,每行一個(gè)。--volumes 打印數(shù)據(jù)卷名,每行一個(gè)。--hash="*" 打印服務(wù)配置散列,每行一個(gè)。為指定的服務(wù)列表設(shè)置“service1,service2”,或使用通配符來(lái)顯示所有服務(wù)。案例:
無(wú)選項(xiàng)
–resolve-image-digests
-q, --quiet
–services
–volumes
–hash="*"
docker-compose stop
Stops running containers without removing them. They can be started again with docker-compose start.
停止運(yùn)行容器而不移除它們。它們可以通過(guò)docker-compose start重新啟動(dòng)。
原文:
Usage: stop [options] [SERVICE...]Options:-t, --timeout TIMEOUT Specify a shutdown timeout in seconds.(default: 10)翻譯:
使用方法: stop [選項(xiàng)] [SERVICE...]選項(xiàng):-t, --timeout TIMEOUT 指定關(guān)機(jī)超時(shí)時(shí)間(以秒為單位)。(默認(rèn)值:10)案例:
List item
List item
List item
List item
List item
docker-compose kill
Forces running containers to stop by sending a SIGKILL signal. Optionally the signal can be passed, for example:
通過(guò)發(fā)送SIGKILL信號(hào)來(lái)強(qiáng)制運(yùn)行容器停止。可選的信號(hào)可以被傳遞,例如:
docker-compose kill -s SIGINT
原文:
Usage: kill [options] [SERVICE...]Options:-s SIGNAL SIGNAL to send to the container.Default signal is SIGKILL.翻譯:
使用方法: kill [選項(xiàng)] [SERVICE...]選項(xiàng):-s SIGNAL 發(fā)送信號(hào)給容器。默認(rèn)信號(hào)是SIGKILL。案例:
原文:
翻譯:
案例:
原文:
翻譯:
案例:
原文:
翻譯:
案例:
原文:
翻譯:
案例:
原文:
翻譯:
案例:
原文:
翻譯:
案例:
原文:
翻譯:
案例:
原文:
翻譯:
案例:
原文:
翻譯:
案例:
原文:
翻譯:
案例:
原文:
翻譯:
案例:
原文:
翻譯:
案例:
總結(jié)
以上是生活随笔為你收集整理的docker-compose命令介绍和使用【官方英文文档翻译】【附加案例】的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 前端_网页编程 节流
- 下一篇: 小程序开发(2)-之app.js、app