eclipse-theia / theia

Eclipse Theia is a cloud & desktop IDE framework implemented in TypeScript.
http://theia-ide.org
Eclipse Public License 2.0
19.9k stars 2.49k forks source link

Using Theia IDE with a shared Docker volume. No space left on device #5842

Open stefanbschneider opened 5 years ago

stefanbschneider commented 5 years ago

Description

I have my own web app in a Docker container. To persist files generated with this I use a named Docker volume. I now want to edit these files with Thea IDE. My idea was to simply use the same Docker volume and share it between the two Docker containers.

When specifying the volume for Theia, I can see all the generated files in the IDE, but I cannot edit, remove, or create files. I always get an error root ERROR Request setContent failed with error: ENOSPC: no space left on device, write Error: ENOSPC: no space left on device, write.

What can I do to solve this? Would it help to install my web app and Theia in a single Docker container?

I saw this related issue https://github.com/theia-ide/theia/issues/3276, but it's not discussing Docker volumes and didn't help me resolve my issue.

Reproduction Steps

This is the Docker compose file that I use to start both my Docker container and the container of Theia with the shared volume: https://github.com/stefanbschneider/tng-sdk-project/blob/dev/general/docker-compose.yml

docker-compose up

Should start both and show the described behavior.

OS and Theia version:

akosyakov commented 5 years ago

I assume you checked already that you indeed have space. If it is so, then try: https://github.com/theia-ide/theia/blob/master/doc/Developing.md#linux

stefanbschneider commented 5 years ago

I assume you checked already that you indeed have space.

Yes, on my PC still have plenty of space left (multiple 100GB). The space of the Docker volume itself isn't limited, is it?

If it is so, then try: https://github.com/theia-ide/theia/blob/master/doc/Developing.md#linux

How/where would I run this command? I tried running it inside the Theia container after starting it, but it doesn't work:

bash-4.4$ echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf
 && sudo sysctl -p
bash: sudo: command not found
bash-4.4$ echo fs.inotify.max_user_watches=524288 | tee -a /etc/sysctl.conf && s
ysctl -p
tee: /etc/sysctl.conf: Permission denied
fs.inotify.max_user_watches=524288
bash-4.4$
akosyakov commented 5 years ago

I think you should increase it on your host os.

stefanbschneider commented 5 years ago

Increase what? And how?

akosyakov commented 5 years ago

Increase what?

increase your default inotify watches. from https://github.com/theia-ide/theia/blob/master/doc/Developing.md#linux

And how?

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p from https://github.com/theia-ide/theia/blob/master/doc/Developing.md#linux

stefanbschneider commented 5 years ago

I'm running Docker on Windows; this command won't work on my machine.

akosyakov commented 5 years ago

@stefanbschneider sorry, missed it

@kittaakos maybe you came across this error? or someone from @marcdumais-work team?

marcdumais-work commented 5 years ago

Hi @stefanbschneider

I'm running Docker on Windows; this command won't work on my machine.

I think none of us regularly use Windows, nevermind docker on Windows, so please bear with us...

Do you use Windows shared drives? If so there are limitations, documented in the link.

As well, on Linux and in Linux containers, Theia uses inotify to watch files and folders in the workspace. This is a Linux kernel mechanism, that's apparently not supported in Docker on Windows, for shared drives (not sure if it's your case). See "INOTIFY ON SHARED DRIVES DOES NOT WORK". See also the "PERMISSIONS ERRORS ON DATA DIRECTORIES FOR SHARED VOLUMES" section from same link.

I'm running Docker on Windows; this command won't work on my machine.

I found this w-a, not sure if it might help: https://github.com/docker/for-win/issues/2011

stefanbschneider commented 5 years ago

Small update:

stefanbschneider commented 5 years ago

I now tried running without Docker volume but exactly how specified on your website on Ubuntu:

docker run -it --init -p 3000:3000 -v "$(pwd):/home/project:cached" theiaide/theia:latest

I fixed the error message regarding inotify as described above:

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p 

But I still cannot create or edit any files!

root ERROR Request createFile failed with error: EACCES: permission denied, open '/home/project/test.txt' Error: EACCES: permission denied, open '/home/project/test.txt'
stefanbschneider commented 5 years ago

If I test running the same command, again on Ubuntu, but with -v "$(pwd)" instead of -v "$(pwd):/home/project:cached", it works and I can create and save files. But I don't see the files of my computer in pwd and vice versa I don't see the newly created files by Theia either.

Once I add the /home/project part to the volume, I can see the files again, but can't edit them in Theia or create new ones...

Could you elaborate what I need to consider when specifying the volume, when not using Docker volume?

akosyakov commented 5 years ago

Have you granted access inside docker to this folders, like here: https://github.com/theia-ide/theia-apps/blob/7e5031cf3602a3bd59c7bb441e8882e244c98caa/theia-docker/Dockerfile#L22

@marcdumais-work Maybe you can help? or @sr229

sr229 commented 5 years ago

Toolbox isn't exactly a type of flexible machine. It runs a minimal Linux distro with Docker and that's about it. I'll check if this replicates on a Linux environment.

sr229 commented 5 years ago

Tested with Google Cloud Shell and PWD Labs and I was not able to reliably reproduce this. Docker for Windows is not exactly as full featured as its POSIX cousins so you'll need WSL2 as a workaround for now.

stefanbschneider commented 5 years ago

I'm not talking about Windows anymore at this point. My last to comments, with the access problem were referring to Ubuntu.

sr229 commented 5 years ago

I'm not talking about Windows anymore at this point. My last to comments, with the access problem were referring to Ubuntu.

My mistake, sorry 😅 . I can't reproduce that as well however during my tests with the following environments as well. They were able to access the files as intended. Not sure how did you end up with that, but I'm pretty certain that :cached is causing issues with your mount. I also believe your mount's files is owned by root which theia has no access to (which is a notorious permission issue with Docker as well).

Try doing ls -al inside the Theia container to confirm my assumption.

stefanbschneider commented 5 years ago

Inside Theia when started with docker run -it --init -p 3000:3000 -v "$(pwd):/home/project" theiaide/theia:latest:

bash-4.4$ ls -al
total 436
drwxr-sr-x    1 theia    theia         4096 Aug  9 12:46 .
drwxrwxr-x    1 root     root          4096 Aug  9 01:32 ..
drwxr-sr-x    3 theia    theia         4096 Aug  9 12:46 .cache
drwx--S---    3 theia    theia         4096 Aug  9 12:46 .config
drwxr-sr-x    4 theia    theia         4096 Aug  9 12:46 .npm
-rw-r--r--    1 theia    theia          492 Aug  9 01:32 .yarnclean
drwxr-xr-x    3 theia    theia         4096 Aug  9 01:31 lib
drwxr-xr-x  383 theia    theia        16384 Aug  9 01:32 node_modules
-rw-rw-r--    1 theia    theia         1151 Aug  9 01:28 package.json
drwxr-xr-x    4 theia    theia         4096 Aug  9 01:30 src-gen
-rw-r--r--    1 theia    theia         4176 Aug  9 01:30 webpack.config.js
-rw-r--r--    1 theia    theia       378359 Aug  9 01:32 yarn.lock
sr229 commented 5 years ago

Thank you, I tried my take and this is what I have in my lab test

bash-4.4$ ls -al
total 72
drwxr-xr-x    9 root     root          4096 Aug  9 12:47 .
drwxrwxr-x    1 root     root            19 Aug  9 01:32 ..
-rw-r--r--    1 root     root            30 Aug  9 12:46 .dockerignore
drwxr-xr-x    8 root     root           163 Aug  9 12:47 .git
-rw-r--r--    1 root     root          1206 Aug  9 12:46 .gitignore
-rw-r--r--    1 root     root          1775 Aug  9 12:46 Dockerfile
-rw-r--r--    1 root     root          2238 Aug  9 12:46 Jenkinsfile
-rw-r--r--    1 root     root         10141 Aug  9 12:46 LICENSE
-rw-r--r--    1 root     root            54 Aug  9 12:46 MANIFEST.in
-rw-r--r--    1 root     root          9455 Aug  9 12:46 README.md
-rw-r--r--    1 root     root          1972 Aug  9 12:46 docker-compose.yml
drwxr-xr-x    2 root     root            27 Aug  9 12:47 docs
drwxr-xr-x    2 root     root           204 Aug  9 12:47 example-project
drwxr-xr-x    6 root     root            68 Aug  9 12:47 pipeline
-rwxr-xr-x    1 root     root           562 Aug  9 12:46 pipeline_local.sh
drwxr-xr-x    2 root     root            23 Aug  9 12:47 projects
-rw-r--r--    1 root     root            51 Aug  9 12:46 pytest.ini
-rw-r--r--    1 root     root           144 Aug  9 12:46 requirements.txt
-rw-r--r--    1 root     root            59 Aug  9 12:46 setup.cfg
-rwxr-xr-x    1 root     root          2965 Aug  9 12:46 setup.py
drwxr-xr-x    4 root     root            51 Aug  9 12:47 src
drwxr-xr-x    2 root     root           193 Aug  9 12:47 tests

It's pretty evident theia can't really access the files even they have the proper permissions because they're owned by root but you have never granted theia to write on root's folder, which you just bind-mounted.

sr229 commented 5 years ago

Keep in mind this lines right here are intended to help with PVs or folders just bind mounted from a local directory (which Docker has permission to write to anyways), Docker to Docker PV mounting is a different beast to most use cases of this line.

https://github.com/theia-ide/theia-apps/blob/7e5031cf3602a3bd59c7bb441e8882e244c98caa/theia-docker/Dockerfile#L22-L25

marcdumais-work commented 5 years ago

Hi @stefanbschneider ,

If I test running the same command, again on Ubuntu, but with -v "$(pwd)" instead of -v "$(pwd):/home/project:cached", it works and I can create and save files. But I don't see the files of my computer in pwd and vice versa I don't see the newly created files by Theia either.

What's happening is that the volume is not mounted to /home/project in the container, and so what you create in that folder, from inside the container, will be only visible in the container. This is the same as not mentioning the -v switch at all.

Could you elaborate what I need to consider when specifying the volume

The permission issues you have are expected, and a generic Docker issue when sharing files between a host and container using a volume. What happens is that inside the container, the theia user is different than your user on the host. You can use the id -u and id -g commands to confirm (respectively user id and current main group id) - the user name/group names do not matter, just the ids, when it comes to permissions on Linux.

If you are looking for a solution specifically for yourself, one option would be to modify the image you use and have the theia user created in the image using your host uid/gid, and then you could access the same files from both without these issues.

A more generic solution is more involved, but could entail not creating the container user (theia in this case) as part of the image, but rather create it in each container, using the user's uid/gid to do so.

We have a PR under review, where the author has done exactly that, using docker exec to create a user with aligned permissions, subsequently to container creation (docker run): https://github.com/theia-ide/theia-apps/blob/a85e977c9d75a6f930aa8f9f939cf3c818259844/theia-rust-docker/ex_bash#L164-L168

stefanbschneider commented 5 years ago

Hm. Lastly, I was just trying to run Theia - even without another Docker container using the same volume. But I can't create/edit files. Because locally I use a different user than theia?

If it works for files within the container, I'm thinking to simply build a Dockerfile that builds and then runs both Theia and my own applicaiton in a single Docker without any volume.

I thought this would be quite easy to do with Docker multi-stage build, but I'm still struggeling to get this to work:

FROM python:3.6-slim
RUN pip install
# other stuff to install my app
CMD ["myapp"]

FROM theiaide/theia:latest
CMD [ "node", "/home/theia/src-gen/backend/main.js", "/home/project", "--hostname=0.0.0.0" ]

Unfortunately, building and running this, only Theia works but not my app. If I swap the order in the Dockerfile, it's vice versa. Can't get both to run...

marcdumais-work commented 5 years ago

I can't create/edit files. Because locally I use a different user than theia?

Correct - the uid/gid would not be aligned between your host user and container user (the label associated to the users do not matter - so having a theia user in both that have different ids would not help)

If it works for files within the container, I'm thinking to simply build a Dockerfile that builds and then runs both Theia and my own application in a single Docker without any volume.

+1, that should work fine permission-wise.

marcdumais-work commented 5 years ago

Unfortunately, building and running this, only Theia works but not my app. If I swap the order in the Dockerfile, it's vice versa. Can't get both to run...

I think by default the different stages share nothing; you would need to use COPY to bring over stuff you need from the first stage into the second one. This works well when what you want to copy is all contained in a single folder, like a Theia app, but not so well when spread all over the place, like installed Debian packages tend to do.

Whichever order you chose, this looks not trivial in this case.