docker-compose常用命令及使用詳情
一、介紹
原始碼:https://github.com/docker/compose
官方文件:https://docs.docker.com/glossary/?term=amd64
安裝:https://docs.docker.com/compose/install/
二、常用命令
· build(構建yml中某個服務的映象)
如上,web這個服務是依賴於映象build的。在本地 也存在Dockerfile檔案。
可以使用docker-compose build來構建服務的映象。
· ps(檢視已經啟動的服務狀態)
· kill(停止某個服務)
· logs(可以檢視某個服務的log)
· port(列印繫結的public port)
· pull(pull服務映象)
· up(啟動yml定義的所有服務)
· stop(停止yml中定義的所有服務)
· start(啟動被停止的yml中的所有服務)
· kill(強行停止yml中定義的所有服務)
· rm(刪除yml中定義的所有服務)
· restart(重啟yml中定義的所有服務)
· scale(擴充套件某個服務的個數,可以向上或向下)
· migrate-to-labels(這個沒有實際嘗試。根據介紹是將服務從1.2遷移到1.3帶labels的版本。docker之前不支援label)
Define and run multi-container applications with Docker.
Usage:
docker-compose [-f=<arg>...] [options] [COMMAND] [ARGS...]
docker-compose -h|--help
Options:
-f, --file FILE Specify an alternate compose file (default: docker-compose.yml)
-p, --project-name NAME Specify an alternate project name (default: directory name)
--verbose Show more output
-v, --version Print version and exit
-H, --host HOST Daemon socket to connect to
--tls Use TLS; implied by --tlsverify
--tlscacert CA_PATH Trust certs signed only by this CA
--tlscert CLIENT_CERT_PATH Path to TLS certificate file
--tlskey TLS_KEY_PATH Path to TLS key file
--tlsverify Use TLS and verify the remote
--skip-hostname-check Don't check the daemon's hostname against the name specified
in the client certificate (for example if your docker host
is an IP address)
Commands:
build Build or rebuild services
config Validate and view the compose file
create Create services
down Stop and remove containers, networks, images, and volumes
events Receive real time events from containers
help Get help on a command
kill Kill containers
logs View output from containers
pause Pause services
port Print the public port for a port binding
ps List containers
pull Pulls service images
restart Restart services
rm Remove stopped containers
run Run a one-off command
scale Set number of containers for a service
start Start services
stop Stop services
unpause Unpause services
up Create and start containers
version Show the Docker-Compose version information
build
Usage: build [options] [SERVICE...]
Options:
config
Usage: config [options]
create
為服務建立容器.只是單純的create,還需要使用start啟動compose
Usage: create [options] [SERVICE...]
--build 建立容器前,生成映象.
Usage: down [options]
attached to containers.
--remove-orphans Remove containers for services not defined in the
events
Usage: events [options] [SERVICE...]
{
"service": "web",
"event": "create",
"container": "213cf75fc39a",
"image": "alpine:edge",
"time": "2015-11-20T18:01:03.615550",
}
exec
Usage: exec [options] SERVICE COMMAND [ARGS...]
Options:
-d 分離模式,後臺執行命令.
--privileged 獲取特權.
--user USER 指定執行的使用者.
-T 禁用分配TTY. By default `docker-compose exec`
docker-compose exec web sh
kill
Usage: kill [options] [SERVICE...]
$ docker-compose kill -s SIGINT
logs
Usage: logs [options] [SERVICE...]
Options:
pause
Usage: pause [SERVICE...]
unpause
Usage: unpause [SERVICE...]
port
Usage: port [options] SERVICE PRIVATE_PORT
Options:
--protocol=proto tcp or udp [default: tcp]
--index=index index of the container if there are multiple
instances of a service [default: 1]
ps
Usage: ps [options] [SERVICE...]
Options:
-q 只顯示ID
pull
Usage: pull [options] [SERVICE...]
push
Usage: push [options] [SERVICE...]
Options:
restart
Usage: restart [options] [SERVICE...]
Options:
-t, --timeout TIMEOUT Specify a shutdown timeout in seconds. (default: 10)
rm
Usage: rm [options] [SERVICE...]
Options:
-a, --all Also remove one-off containers created by
By default, anonymous volumes attached to containers will not be removed. You can override this with -v
. To list all volumes, use docker volume ls
.
run
Usage: run [options] [-e KEY=VAL...] SERVICE [COMMAND] [ARGS...]
-T 禁用TTY.
啟動web伺服器,並執行bash命令.
$ docker-compose run web bash
$ docker-compose run --service-ports web python manage.py shell
$ docker-compose run --publish 8080:80 -p 2022:22 -p 127.0.0.1:2021:21 web python manage.py shell
$ docker-compose run db psql -h db -U docker
不linke容器,單獨啟動指定容器:
$ docker-compose run --no-deps web python manage.py shell
start
Usage: start [SERVICE...]
stop
Usage: stop [options] [SERVICE...]
Options:
up
Usage: up [options] [SERVICE...]
Options:
-d 後臺執行,輸出容器的名字.
Incompatible with --abort-on-container-exit.
--no-deps 不啟動link服務.
Incompatible with --no-recreate.
Incompatible with --force-recreate.
--abort-on-container-exit 任何容器停止,自動停止所有容器.
相關文章
- docker、docker-compose 常用命令Docker
- gulp使用詳情 及 3.0到4.0的坑
- Docker-compose 常用命令和模板Docker
- docker-compose 配置檔案內容詳解以及常用命令介紹Docker
- SQLmap常用命令使用詳解SQL
- Vue中混入的使用詳情Vue
- 如何使用Java呼叫商品詳情APIJavaAPI
- Ubuntu安裝Docker及Docker-composeUbuntuDocker
- Linux下 netstat ps kill 命令詳解及常用命令收集Linux
- docker-compose 使用例項Docker
- 使用 makefile 管理 docker-composeDocker
- 資料庫 MySQL8.0+常用命令及操作命令詳解資料庫MySql
- 淘寶詳情APi介面的使用方式API
- lazada商品詳情API介面運用場景及功能API
- mysql 資料插入和更新及刪除詳情FSSHMySql
- 7、docker-compose安裝使用Docker
- 使用docker-compose管理freeswitch容器Docker
- 關於docker-Compose基本使用Docker
- sessionId詳情Session
- 使用Python呼叫商品詳情API的全面指南PythonAPI
- 使用API介面獲取拼多多商品詳情API
- Git常用命令符和GitHub使用教程圖文詳解Github
- linux常用命令詳解Linux
- Git 常用命令詳解Git
- Linux常用命令-詳細Linux
- Git詳解及github的使用Github
- 用Java使用API介面獲取Lazada商品詳情JavaAPI
- 使用商品詳情API介面獲取商品資料API
- 商品詳情API介面怎麼被程式猿使用API
- 詳解gitignore的使用方法,讓你盡情使用git add .Git
- winscp使用教程多使用者,winscp使用教程多使用者,教程詳情
- 京東詳情介面的營銷方案及資料返回展示
- 淘寶詳情api介面獲取的方式及簡單示例API
- podman安裝和普通使用者使用podman的方式及podman常用命令
- 關於docker-compose up -d 出現超時情況處理Docker
- dva框架使用詳解及Demo教程框架
- 使用 docker-compose 搭建 Laravel 環境 (三)DockerLaravel
- 使用docker-compose構建elasticsearch叢集DockerElasticsearch