Docker 安裝- docker-compose


如何在 linux 上安裝 docker-compose

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

確認 docker-compose 本版

確認完成後,請進行以下指令,進行安裝

  • sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  • sudo chmod +x /usr/local/bin/docker-compose
[root@localhost]# chown -R $(whoami) /usr/local/bin
[root@localhost]# sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(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   633  100   633    0     0   2365      0 --:--:-- --:--:-- --:--:--  2361
100 11.6M  100 11.6M    0     0  6874k      0  0:00:01  0:00:01 --:--:-- 10.3

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

在線升級

  • 先刪除本地的 docker-compose rm /usr/local/bin/docker-compose
  • 再進行一次 安裝流程即可
[root@localhost]# sudo rm /usr/local/bin/docker-compose
[root@localhost]# sudo curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(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   633  100   633    0     0   2365      0 --:--:-- --:--:-- --:--:--  2361
100 11.6M  100 11.6M    0     0  6874k      0  0:00:01  0:00:01 --:--:-- 10.3

[root@localhost]# sudo chmod +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"

, ,