现象

当安装好docker-compose之后,在命令行执行docker-compose up,会出现如下报错:

  1. 1Traceback (most recent call last):
  2. 2File "urllib3/connectionpool.py", line 677, in urlopen
  3. 3File "urllib3/connectionpool.py", line 392, in _make_request
  4. 4File "http/client.py", line 1252, in request
  5. 5File "http/client.py", line 1298, in _send_request
  6. 6File "http/client.py", line 1247, in endheaders
  7. 7File "http/client.py", line 1026, in _send_output
  8. 8File "http/client.py", line 966, in send
  9. 9File "docker/transport/unixconn.py", line 43, in connect
  10. 10FileNotFoundError: [Errno 2] No such file or directory
  11. 11
  12. 12During handling of the above exception, another exception occurred:
  13. 13
  14. 14Traceback (most recent call last):
  15. 15File "requests/adapters.py", line 449, in send
  16. 16File "urllib3/connectionpool.py", line 727, in urlopen
  17. 17File "urllib3/util/retry.py", line 403, in increment
  18. 18File "urllib3/packages/six.py", line 734, in reraise
  19. 19File "urllib3/connectionpool.py", line 677, in urlopen
  20. 20File "urllib3/connectionpool.py", line 392, in _make_request
  21. 21File "http/client.py", line 1252, in request
  22. 22File "http/client.py", line 1298, in _send_request
  23. 23File "http/client.py", line 1247, in endheaders
  24. 24File "http/client.py", line 1026, in _send_output
  25. 25File "http/client.py", line 966, in send
  26. 26File "docker/transport/unixconn.py", line 43, in connect
  27. 27urllib3.exceptions.ProtocolError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
  28. 28
  29. 29During handling of the above exception, another exception occurred:
  30. 30
  31. 31Traceback (most recent call last):
  32. 32File "docker/api/client.py", line 205, in _retrieve_server_version
  33. 33File "docker/api/daemon.py", line 181, in version
  34. 34File "docker/utils/decorators.py", line 46, in inner
  35. 35File "docker/api/client.py", line 228, in _get
  36. 36File "requests/sessions.py", line 543, in get
  37. 37File "requests/sessions.py", line 530, in request
  38. 38File "requests/sessions.py", line 643, in send
  39. 39File "requests/adapters.py", line 498, in send
  40. 40requests.exceptions.ConnectionError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
  41. 41
  42. 42During handling of the above exception, another exception occurred:
  43. 43
  44. 44Traceback (most recent call last):
  45. 45File "bin/docker-compose", line 3, in
  46. 46File "compose/cli/main.py", line 67, in main
  47. 47File "compose/cli/main.py", line 123, in perform_command
  48. 48File "compose/cli/command.py", line 69, in project_from_options
  49. 49File "compose/cli/command.py", line 132, in get_project
  50. 50File "compose/cli/docker_client.py", line 43, in get_client
  51. 51File "compose/cli/docker_client.py", line 170, in docker_client
  52. 52File "docker/api/client.py", line 188, in init
  53. 53File "docker/api/client.py", line 213, in _retrieve_server_version
  54. 54docker.errors.DockerException: Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

解决方案

一般而言,主要有三个原因导致,可以依次排查

  1. 如果当前用户没有系统管理员的权限,就需要加sudo,即sudo docker-compose up

  2. 是否安装了docker。也就是说,要先安装docker,再安装docker-compose

  3. 内存太小,比如只有1G内存