QuantConnect / lean-cli

CLI for running the LEAN engine locally and in the cloud
https://www.lean.io/cli
Apache License 2.0
191 stars 100 forks source link

Docker issue on Windows #144

Closed A-Anthony closed 1 year ago

A-Anthony commented 1 year ago

When I try either the "research" command or the "optimize" command, a Docker container fails to run from the image. When I run the images manually from Docker it will start but then I don't know how to point LEAN to that container.

The containers are created but won't run, here is the error produced in Docker when trying to run those LEAN-initialized containers:

Error invoking remote method 'docker-start-container': Error: (HTTP code 400) unexpected - invalid mount config for type "bind": bind source path does not exist: /run/desktop/mnt/host/c/Users/USERNAME/AppData/Local/Temp/lean-cli-4tad_tt1/config.json

There is a troubleshooting section related to file sharing on a Mac that looks similar, but this is Windows and should be automatically sharing using the WSL 2 configuration.

and here is the verbose output from the actual lean "research" command: Running 'quantconnect/research:latest' with the following configuration: { 'environment': {}, 'stop_signal': 'SIGKILL', 'mounts': [ {'Target': '/Lean/Launcher/bin/Debug/config.json', 'Source': 'C:\Users\USERNAME\AppData\Local\Temp\lean-cli-g1fi7ytx\config.json', 'Type': 'bind', 'ReadOnly': True}, {'Target': '/Lean/Launcher/bin/Debug/Notebooks/config.json', 'Source': 'C:\Users\USERNAME\AppData\Local\Temp\lean-cli-g1fi7ytx\config.json', 'Type': 'bind', 'ReadOnly': True}, {'Target': '/lean-cli-start.sh', 'Source': 'C:\Users\USERNAME\AppData\Local\Temp\lean-cli-q_k51y93\lean-cli-start.sh', 'Type': 'bind', 'ReadOnly': True} ], 'volumes': { 'C:\LEAN\data': {'bind': '/Lean/Data', 'mode': 'rw'}, 'C:\Users\USERNAME\AppData\Local\Temp\lean-cli-g0fj5jnk': {'bind': '/Results', 'mode': 'rw'}, 'C:\LEAN\test_project\storage': {'bind': '/Storage', 'mode': 'rw'}, 'C:\LEAN\test_project': {'bind': '/Lean/Launcher/bin/Debug/Notebooks', 'mode': 'rw'} }, 'ports': {'8888': '8888'}, 'name': 'lean_cli_b65af7dd83b0416eb3dd594770416c62', 'entrypoint': ['bash', '/lean-cli-start.sh'], 'detach': True, 'hostname': 'DESKTOP-NAME', 'tty': True, 'stdin_open': True, 'network': 'lean_cli' } Traceback (most recent call last): File "c:\users\USERNAME\appdata\local\programs\python\python38-32\lib\site-packages\docker\api\client.py", line 268, in _raise_for_status response.raise_for_status() File "c:\users\USERNAME\appdata\local\programs\python\python38-32\lib\site-packages\requests\models.py", line 960, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: http+docker://localnpipe/v1.41/containers/1562dd88cbd8a1409a5337199659a0ad062e562af2328efb1588c118b0d9fecd/start

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "c:\users\USERNAME\appdata\local\programs\python\python38-32\lib\site-packages\lean\main.py", line 103, in main lean.main(standalone_mode=False) File "c:\users\USERNAME\appdata\local\programs\python\python38-32\lib\site-packages\click\core.py", line 1053, in main rv = self.invoke(ctx) File "c:\users\USERNAME\appdata\local\programs\python\python38-32\lib\site-packages\click\core.py", line 1659, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx)) File "c:\users\USERNAME\appdata\local\programs\python\python38-32\lib\site-packages\lean\click.py", line 125, in invoke result = super().invoke(ctx) File "c:\users\USERNAME\appdata\local\programs\python\python38-32\lib\site-packages\click\core.py", line 1395, in invoke
return ctx.invoke(self.callback, ctx.params) File "c:\users\USERNAME\appdata\local\programs\python\python38-32\lib\site-packages\click\core.py", line 754, in invoke return __callback(args, kwargs) File "c:\users\USERNAME\appdata\local\programs\python\python38-32\lib\site-packages\lean\commands\research.py", line 165, in
research raise error File "c:\users\USERNAME\appdata\local\programs\python\python38-32\lib\site-packages\lean\commands\research.py", line 156, in
research container.docker_manager().run_image(research_image,
run_options) File "c:\users\USERNAME\appdata\local\programs\python\python38-32\lib\site-packages\lean\components\docker\docker_manager.py",
line 167, in run_image container = docker_client.containers.run(str(image), None, kwargs) File "c:\users\USERNAME\appdata\local\programs\python\python38-32\lib\site-packages\docker\models\containers.py", line 826, in
run container.start() File "c:\users\USERNAME\appdata\local\programs\python\python38-32\lib\site-packages\docker\models\containers.py", line 404, in
start return self.client.api.start(self.id,
kwargs) File "c:\users\USERNAME\appdata\local\programs\python\python38-32\lib\site-packages\docker\utils\decorators.py", line 19, in
wrapped return f(self, resource_id,
args,
kwargs) File "c:\users\USERNAME\appdata\local\programs\python\python38-32\lib\site-packages\docker\api\container.py", line 1109, in
start self._raise_for_status(res) File "c:\users\USERNAME\appdata\local\programs\python\python38-32\lib\site-packages\docker\api\client.py", line 270, in
_raise_for_status raise create_api_error_from_http_exception(e) File "c:\users\USERNAME\appdata\local\programs\python\python38-32\lib\site-packages\docker\errors.py", line 31, in create_api_error_from_http_exception raise cls(e, response=response, explanation=explanation) docker.errors.APIError: 400 Client Error for http+docker://localnpipe/v1.41/containers/1562dd88cbd8a1409a5337199659a0ad062e562af2328efb1588c118b0d9fecd/start: Bad Request
("network lean_cli is ambiguous (2 matches found on name)")

Any ideas?

Thank you, Ari

Martin-Molinero commented 1 year ago

Hey @A-Anthony!

Error invoking remote method 'docker-start-container': Error: (HTTP code 400) unexpected - invalid mount config for type "bind": bind source path does not exist: /run/desktop/mnt/host/c/Users/USERNAME/AppData/Local/Temp/lean-cli-4tad_tt1/config.json There is a troubleshooting section related to file sharing on a Mac that looks similar, but this is Windows and should be automatically sharing using the WSL 2 configuration.

WSL 2 configuration

A-Anthony commented 1 year ago

Thank you @Martin-Molinero.

I disabled the WSL 2 engine and research (and local backtesting) works now! I haven't tested live or optimization yet but I wouldn't expect issues at this point. I had to reinstall the images when I switched off WSL 2, but I'm new to docker so maybe this makes sense.

It seems the cli was never working locally on my end. I was running a cloud backtest successfully before (sorry for the confusion). I'm not sure if I should keep this open, as the WSL 2 issue persists. As for specs, I'm on Windows 10 with the latest lean version.

Appreciate your help!

Martin-Molinero commented 1 year ago

Hey @A-Anthony! I'm glad to hear it's working correctly for you. I'll close the issue for now, given I can not reproduce in my end with WSL2 engine either, sounds like some windows/docker/wsl engine issue, maybe can try updating them.