Docker-compose fails on Windows with “Error while fetching server API version: (2, ‘CreateFile’, ‘The system cannot find the file specified.’)”

This post was most recently updated on December 1st, 2021.

3 min read.

Once again, I come to you with a surprisingly opaque problem and offer to share my bemusingly simple solution. That should be a dedicated series on my blog – although on second thought, perhaps lobbing 90% of my articles under one tag wouldn’t be helpful… 😁

Problem

When running docker-compose up the command would fail, and instead, output a disgustingly long set of what looks like a whole pile of pythons engaging in quantum entanglement would angrily hiss at you if bothered.

It’s not pretty. And it turns out, it’s (at least in this case) also not descriptive at all!

So the errors I got? See below:

Error while fetching server API version: (2, 'CreateFile', 'The system cannot find the file specified.')

The whole stack trace looks something like below:

Traceback (most recent call last):
   File "docker\api\client.py", line 214, in _retrieve_server_version
   File "docker\api\daemon.py", line 181, in version
   File "docker\utils\decorators.py", line 46, in inner
   File "docker\api\client.py", line 237, in _get
   File "requests\sessions.py", line 543, in get
   File "requests\sessions.py", line 530, in request
   File "requests\sessions.py", line 643, in send
   File "requests\adapters.py", line 439, in send
   File "urllib3\connectionpool.py", line 670, in urlopen
   File "urllib3\connectionpool.py", line 392, in _make_request
   File "http\client.py", line 1255, in request
   File "http\client.py", line 1301, in _send_request
   File "http\client.py", line 1250, in endheaders
   File "http\client.py", line 1010, in _send_output
   File "http\client.py", line 950, in send
   File "docker\transport\npipeconn.py", line 32, in connect
   File "docker\transport\npipesocket.py", line 23, in wrapped
   File "docker\transport\npipesocket.py", line 72, in connect
   File "docker\transport\npipesocket.py", line 52, in connect
 pywintypes.error: (2, 'CreateFile', 'The system cannot find the file specified.')
 During handling of the above exception, another exception occurred:
 Traceback (most recent call last):
   File "docker-compose", line 3, in 
   File "compose\cli\main.py", line 81, in main
   File "compose\cli\main.py", line 199, in perform_command
   File "compose\cli\command.py", line 60, in project_from_options
   File "compose\cli\command.py", line 152, in get_project
   File "compose\cli\docker_client.py", line 41, in get_client
   File "compose\cli\docker_client.py", line 170, in docker_client
   File "docker\api\client.py", line 197, in init
   File "docker\api\client.py", line 221, in _retrieve_server_version
 docker.errors.DockerException: Error while fetching server API version: (2, 'CreateFile', 'The system cannot find the file specified.')
 [6316] Failed to execute script docker-compose

Augh. The system cannot find the file specified? API version? What is going on…

Reason

The solution – at least for me – was simple. But before delving into that, let me describe my setup, so you know whether it’ll apply to you or not!

I run Docker on Windows. It’s configured to run on startup and just do it’s the thing – but occasionally it suddenly needs to gulp down over 10Gb or RAM, then proceed to do nothing, and finally require a restart.

The OS itself is fine, it seems to recover nicely. So this time, I just killed the process, waited for a few minutes, and manually ran docker-compose from PowerShell.

That’s when the error was thrown at me. 😳

Solution

I was executing the command from my non-elevated PowerShell window. But that didn’t match how I’ve configured it to run on startup – instead, I needed to run docker-compose from an elevated PowerShell console.

I also realized my Docker Desktop won’t show any of my containers when run non-elevated. I guess that’s kinda obvious, right?

For you, running your stuff elevated (with admin permissions / “as an admin”) or from another user profile, if that’s how it’s configured to run normally, might work.

Stupid? Hey, if it works… 😁

References

mm
5 1 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments