在一次部署的时候遇到了下面的错误提示:
fatal: [51.79.52.209]: FAILED! => {"changed": true, "cmd": "docker compose up -d --remove-orphans", "delta": "0:00:00.210637", "end": "2023-09-15 17:53:15.352525", "msg": "non-zero return code", "rc": 1, "start": "2023-09-15 17:53:15.141888", "stderr": "permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get \"http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json?all=1&filters=%7B%22label%22%3A%7B%22com.docker.compose.config-hash%22%3Atrue%2C%22com.docker.compose.project%3Dmq-service%22%3Atrue%7D%7D\": dial unix /var/run/docker.sock: connect: permission denied", "stderr_lines": ["permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get \"http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json?all=1&filters=%7B%22label%22%3A%7B%22com.docker.compose.config-hash%22%3Atrue%2C%22com.docker.compose.project%3Dmq-service%22%3Atrue%7D%7D\": dial unix /var/run/docker.sock: connect: permission denied"], "stdout": "", "stdout_lines": []}
错误界面。
问题和解决
出现上面错误的原因是我们在服务器上执行 docker compose up -d --remove-orphans
没有执行的权限。
所以我们需要把上面的命令修改为:sud docker compose up -d --remove-orphans