approach to binding a directory (from host machine) to containers $HOME directory #39
Replies: 13 comments 11 replies
-
Here's one such use case I'd like to explore #40 |
Beta Was this translation helpful? Give feedback.
-
Please note that this is a continuation of my answer to the question from the issue #40. I'll split it into several posts, so we can comment each part separately. The procedure described here works starting from the release If you don't need to extend the image and you really want to bind the whole version: "3"
volumes:
my-home-volume
services:
ubuntu-vnc-xfce-g3:
image: accetto/ubuntu-vnc-xfce-g3:latest
ports:
- "25901:5901
- "26901:6901
environment:
VNC_PW: "password"
volumes:
- type: volume
source: my-home-volume
target: /home/headles |
Beta Was this translation helpful? Give feedback.
-
If you'll bind the whole You can mitigate the black screen problem after the container restart by installing the package This is a big difference comparing to the managed environments, as for example Kasm Workspaces. However, the profile will be initialized correctly, if you'll use Docker volumes, as I do in my recommended If you're willing to do some manual work, then you can use the following little trick for initializing your profile in bound directories. However, I haven't had enough time to test it by longer use. It would would be really nice if some of you could help with that. We need to test, how newly created files will be handled. There are pretty big differences in handling the permissions in bound directories on different enwironments. If the pattern will work correctly, then I could automate it later. So see the next post. |
Beta Was this translation helpful? Give feedback.
-
Let's use the following version: "3"
volumes:
my-home-volume:
services:
init:
profiles:
- init-home
image: accetto/ubuntu-vnc-xfce-g3:latest
ports:
- "25901:5901"
- "26901:6901"
environment:
VNC_PW: "password"
volumes:
- type: volume
source: my-home-volume
target: /home/headless
- type: bind
source: ~/shared/my-home
target: /home/headless-copy
final:
profiles:
- shared-home
image: accetto/ubuntu-vnc-xfce-g3:latest
ports:
- "25901:5901"
- "26901:6901"
environment:
VNC_PW: "password"
volumes:
- type: bind
source: ~/shared/my-home/headless
target: /home/headless The Warning! Be sure to use the same password for both containers, otherwise the final container will enter the Be also aware, that on Linux you have to create the folder |
Beta Was this translation helpful? Give feedback.
-
Step 1 We'll use the first container to initialize the Let's call our compose project docker compose --profile init-home -p test -f helper.yml up -d A container |
Beta Was this translation helpful? Give feedback.
-
Step 2 Connect to the container by a VNC viewer (using the port You should see the desktop similar to this: Make sure that you see the "Version Sticker" icon on the desktop. If you don't, then something went wrong. Then you check the content of the If it doesn't, then something went wrong. Move one level up to the parent /home directory. It should look like this: |
Beta Was this translation helpful? Give feedback.
-
Step 3 Copy the complete Open the terminal and from inside the cp -r headless/ headless-copy/ Be sure to make the copy from inside the container. If you do it using the After copying the docker compose --profile init-home -p test -f helper.yml down --volumes Be sure to remove the helper container before creating the final one, because they share the same ports. Optionally you can also modify the |
Beta Was this translation helpful? Give feedback.
-
Step 4 Now we can create the final container that will use the shared docker compose --profile shared-home -p test -f helper.yml up -d Container You can connect to it the same way as it's described above, using the same ports. You should also see the same desktop and the same content of the Note that the VNC password is this time |
Beta Was this translation helpful? Give feedback.
-
Final remarks This approach should work on Windows and also on Linux. I've tested it in following environments:
However, as I've mentioned above, I didn't have enough time for longer testing yet. Especially adding new files from inside and outside the container is a big concern, because the file permissions are handled really differently in different environments. It's probable, that some permission adjustments will be necessary. Personally I would not recommend to bind the whole Binding to external directories was never without challenges and it will probably stay that way also in the future. The environments are simply too different. It's a big difference comparing to the managed environments, as for example Kasm Workspaces. Any help and feedback are welcome. |
Beta Was this translation helpful? Give feedback.
-
I would like to bind the home directory because it makes it easy to encrypt at rest on a medium that is not part of the Docker install. Can you provide more details about why a home directory cannot use bind ? I did have this working a few weeks ago (Ubuntu WSL2 and Windows 10) and am now running into an issue where the home directory appears to be empty inside the container i.e. the bind is not working but no error messages. A minor point: should there be a "headless" group with ID 1000 created? Later... I seem to have the mount working again but it is hard to know why. I suspect it might be the directory I am mounting to the docker container is itself mounted via WSL and I ran |
Beta Was this translation helpful? Give feedback.
-
The bound folder is in WSL's file system (it is a LUKS encrypted SSD mounted in WSL). The reason I ran explorer.exe was a bit random - I was just trying to see if the Docker Desktop might somehow work better if I tried to mount to the Windows path but I never tried that as it started working. If you launch 'explorer.exe .' in a WSL terminal then it will launch Windows explorer in that directory via the Windows path to the WSL directory. I don't think there should be a file systme incompatibility because I'm running in WSL2 so everything is in Linux. I agree that trying to bind a Windows directory to a Linux container is probably very painful but I do not want to do that. I agree that figuring out how to upgrade the system while keeping the home directory as an external directory might be difficult. I wonder if it could be bound during the docker build process too. Permissions should not be too much of an issue because I have a linux directory bound to linux container. We should not need to worry about permissions if the user IDs and group IDs are OK. Having multiple binds and volumes sounds not cool but I can see how you end up there if binding the home is unstable. I think group ID 1000 is missing from your build - I added this to my Dockerfile |
Beta Was this translation helpful? Give feedback.
-
I'm not sure why I had to add that group - I should have got the error you saw. I do see the Version Sticker on the desktop. But I don't understand the purpose of this. What specifically (excluding updating of the base image) will not work with the whole $HOME shared? |
Beta Was this translation helpful? Give feedback.
-
The new User guide contains a section about binding data to my containers. Examples and descriptions of pitfalls are also included. Therefore I'm closing this discussion. Please use the Issues of the User guide project for feedback. |
Beta Was this translation helpful? Give feedback.
-
Opening up this discussion thread for users who have or may want to build and/or run images configured via
docker-compose
and share use cases with exampledocker-compose.yml
filesUpdated by @accetto:
I've renamed this thread from
Building/running images from docker-compose
toapproach to binding a directory (from host machine) to containers $HOME directory
because the actual discussion has turned in that direction. I'll open a new thread namedBuilding/running images from docker-compose
.Beta Was this translation helpful? Give feedback.
All reactions