Unable to run rails server with docker & wsl2
My operating system is Win11, I use docker and wsl2 at the same time, and the code is in the wsl system. When I run rails server I get a docker compose error:
invalid interpolation format for services.web.working_dir: "//wsl$/Ubuntu/data/code/xxx". You may need to escape any $ with another $
The problem is caused by the docker-compose.override.yml file, which has a line :
working_dir: "//wsl$/Ubuntu/data/code/xxx"
Is there something wrong with my configuration?
OS Version: WIN11 21H2 22000.795
WSL2 Version: Ubuntu 20.04.4 LTS
Docker Desktop Version: 4.10.1 (82475)
Rubymine Version: 2022.1.3
请先登录再写评论。
FYI I have spent the last two days (~20 hours) with trial and error, and everything seems to work as expected now when using docker compose, and the project files hosted under WSL2. What I had to do is I had to remove my path mapping from under "Ruby SDK and Gems" and had to add the path mapping under the Run configuration. If it was defined at both places then I got an error when composer tried to start the rails server, with the below error:
So, the path mapping mustn't be defined for the SDK, and must be defined for the run configuration (FYI there is no browse... functionality at the Run configuration path mapping, which also is a minor bug - I had to paste the full wsl$ path there, while the SDK path mapping configurator has a browser icon which defaults to the correct wsl$ path).
If there is no path mapping at all (both the SDK path mappings and the Run configuration path mapping are empty) then the below error is happening:
I hope it helps.
István Ujj-Meszaros just to be sure, have you tried working with Rails with docker-compose SDK when the project resides inside Windows FS?
Hello! The problem seems related to this issue: RUBY-29812. Please upvote it and monitor it for updates. Would it be possible for testing purposes to move the project to Windows FS?
Thanks for the reply, I have solved this problem by adding project path mappings in server configuration, for example
And my previous project was in Windows FS, but it ran so slow that it affected the development work, and it was much better after moving to WSL FS.
Sorry for the offtopic, could you tell me more about your configuration. We would use this information to improve RubyMine. If I understand correctly, your project is in WSL2 FS. Where is your Ruby interpreter located? In docker-compose, WSL2 or on Windows host? What are you using docker-compose with WSL2 for?
Maybe you could share your project?
Because our project is not open source so I'm afraid I can't share it with you, but I can tell you some configuration information. Our development platform is Windows, we use WSL2 and Docker Desktop to run the project, the project is in WSL2 FS, and the Ruby interpreter is in a container run by docker compose. The reason why WSL2 is used is because the project runs very slowly in Windows FS, but it will be much faster in WSL2 FS, which is also officially recommended by Docker: https://docs.docker.com/desktop/windows/wsl/#best-practices
Thanks a lot for your answer!
FYI I was running into a similar issue with Docker+WSL2+Win11.
I am new to Docker so I am not sure if I did everything properly, but everything seem to work well if I open the project from the Windows file system or on a Mac (Ruby interpreter is docker-compose in both cases) but getting the "invalid interpolation format for services.web.working_dir" error if I don't add the path mapping in the Run/Debug configuration. If I add it, then I am running into a different error (missing gems, but thez are installed in the container). If I also add the path mapping under Rubz SDK and Gems then I am running into a third error:
rails | /usr/local/bin/ruby: No such file or directory -- /app/bin/rails (LoadError)
Unfortunately, I can't resolve that last error (FYI the rails service is running without errors if I manually issue "docker compose up" from a WSL terminal).
I have zipped the .idea folder and the docker relevant files if it helps:
https://drive.google.com/file/d/1kQU5bKv72SviLtdwxqFNfiH2pX71q28g/view?usp=sharing
István Ujj-Meszaros, thank you for adding also a comment to the tracker's issue, I'll add here a link so that the other users can check it:
https://youtrack.jetbrains.com/issue/RUBY-29812/-No-SDK-shown-in-Project-settings-under-WSL2DockerDesktopproject-folder-in-WSL
But if your error differs, it'd be great if you could submit a separate issue so that they aren't mixed.
Hey Olga Kuvardina, my issue is probably the exact same issue, and it is now happening in every version of RubyMine that I could try (2022.3 EAP, 2022.2.2, 2022.2.3).
Here is the full output:
Please handle this as very high priority as this error makes WSL2 projects with docker compose to unable to work with, and the fix is probably just to escape the $ character (but it has to be done by the IDE). I have tried to map the path to a drive letter but it seems that a WSL path can't be mapped, unfortunately.
Yes, the same project is working from the Windows FS, but it is running extremely slow, and also there is an issue with webpack-dev-server, it doesn't get notified about the file changes, so it doesn't recompile the scss files on changes.
At the moment there might be problems with how projects located inside WSL2 work, we have a corresponding issue for that:
https://youtrack.jetbrains.com/issue/RUBY-25956/WSL2-ability-to-select-wsl2-host-for-project-location
István Ujj-Meszaros I tried your solution and it didn't work, could you please share screenshots for your solution?
Thanks!