Docker 安裝- docker-compose

如何在 linux 上安裝 docker-compose

因 docker-compose 的版本不同,或是自己的 version 版本問題,請在執行 curl 之前先到官網看一下新的版本

確認 docker-compose 本版


[root@localhost]# chown -R $(whoami) /usr/local/bin
[root@localhost]# curl -L "$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   617    0   617    0     0   2251      0 --:--:-- --:--:-- --:--:--  2243
100 16.4M  100 16.4M    0     0  5739k      0  0:00:02  0:00:02 --:--:-- 8480k

[root@localhost]# chmod a+x /usr/local/bin/docker-compose

查看指令 docker-compose –help

build               Build or rebuild services
bundle              Generate a Docker bundle from the Compose file
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
exec                Execute a command in a running container
help                Get help on a command
images              List images
kill                Kill containers
logs                View output from containers
pause               Pause services
port                Print the public port for a port binding
ps                  List containers
pull                Pull service images
push                Push 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
top                 Display the running processes
unpause             Unpause services
up                  Create and start containers
version             Show the Docker-Compose version information

常用 docker-compose 指令一覽

docker-compose up -d nginx "構建建啟動nignx Container"
docker-compose stop nginx "停止 nignx Container"
docker-compose start nginx "啟動 nignx Container"
docker-compose restart nginx "重新啟動 nginx Container"

docker-compose ps "顯示所有 Container"
docker-compose rm nginx "刪除 Container(刪除前必須關閉 Container)"
docker-compose down "刪除所有 nginx、Container、Image"

docker-compose exec nginx bash "登錄到 nginx Container中"
docker-compose run --no-deps --rm php-fpm php -v "在php-fpm中不啟動關聯 Container,並 Container執行php -v 執行完成後刪除 Container"

docker-compose build nginx "構建 Image"
docker-compose build --no-cache nginx "不帶緩存的構建"

docker-compose logs nginx "查看 nginx 的 Log"
docker-compose logs -f nginx "查看 nginx 的實時 Log"
docker-compose config -q "驗證(docker-compose.yml)文件設定,當設定正確時,不輸出任何內容,當文件設定錯誤,輸出錯誤信息"
docker-compose events --json nginx "以json的形式輸出nginx的docker Log"

docker-compose pause nginx "暫停 nignx Container"
docker-compose unpause nginx "恢復 ningx Container"