# 新版docker自動包含docker compose如需要使用舊版的docker compose 解決方法
**新增docker下載點連結**
`dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo`
**會用到的程式**
```
dnf -y install vim wget epel-release python3-pip
pip3 install --upgrade pip
```
**開始安裝docker此為新版本**
`dnf -y install docker-ce --allowerasing`
**下載舊版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`
**寫入切換的swich**
`curl -fL https://raw.githubusercontent.com/docker/compose-switch/master/install_on_linux.sh | sh `
**手動安裝
下載適用於您的體系結構的 compose-switch 二進製文件**
`curl -fL https://github.com/docker/compose-switch/releases/latest/download/docker-compose-linux-amd64 -o /usr/local/bin/compose-switch`
**使 compose-switch 可執行**
`chmod +x /usr/local/bin/compose-switch`
**重新命名docker-compose二進製文件,因為是不同版本因此使用 v1來區分/usr/local/bin/docker-compose-v1**
`mv /usr/local/bin/docker-compose /usr/local/bin/docker-compose-v1`
**docker-compose為命令定義一個“替代”組**
```
update-alternatives --install /usr/local/bin/docker-compose docker-compose /usr/local/bin/dicker-compose-v1 1
```
```
update-alternatives --install /usr/local/bin/docker-compose docker-compose /usr/local/bin/compose-switch 99
```
檢查安裝
`update-alternatives --display docker-compose`
# ******版本切換指令
想要更改docker的版本就可以使用這個指令
` update-alternatives --config docker-compose`
# 更改服務啟動起始位置
```
mkdir /home/docker
vim /lib/systemd/system/docker.service
```
# 更改其中的內容 docker版本低於1.20
```ini=
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
BindsTo=containerd.service
After=network-online.target firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H fd:// containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always
# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3
# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
[Install]
WantedBy=multi-user.target
```
# 若docker版本高於1.20,則改成如下:
```ini=9
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd --data-root /home/docker
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always
```
## 啟動服務
`systemctl daemon-reload`
`systemctl enable docker`
`systemctl start docker`
如果ps狀態一直為restaring可以試試把普羅米修斯的資覅夾data權限改為777
chomod 777 data
此處的data為普羅米修斯的data會因為權限不足而無法開啟故須更改權限
參考資料 https://hackmd.io/P_3HM5jRTf-VWEhRxanB5g