Thanks to visit codestin.com
Credit goes to github.com

Skip to content

/home/coder volume is not being persisted on docker containers starting on version v2.18 #16188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
caiodelgadonew opened this issue Jan 18, 2025 · 7 comments · Fixed by #16189
Assignees
Labels
s2 Broken use cases or features (with a workaround). Only humans may set this.

Comments

@caiodelgadonew
Copy link

caiodelgadonew commented Jan 18, 2025

Starting a coder using the docker-compose provided in the documentation from a fresh install and using the default docker containers template, when starting the container coder does not creates the user within the container and fallback to coder user, leading to issues on defining the host volume that is owned by the current user and not coder, which means after a update of the template all data is gone,

This affects versions v2.18.1 and v2.18.2

However the version v2.17.3 seems working as expected.

Screenshots for v2.18+

Image
Image
Image
Image

Screenshot for v2.17.3

Image

@coder-labeler coder-labeler bot added the bug risk Prone to bugs label Jan 18, 2025
@matifali
Copy link
Member

matifali commented Jan 18, 2025

Hi, @caiodelgadonew
In the built-in docker template, we switched to a docker image resource to pull a pre-built image instead of building from the Dockerfile. This pre built image has a user with the name coder.

@phorcys420 can you take a look?

@matifali matifali added s2 Broken use cases or features (with a workaround). Only humans may set this. and removed bug risk Prone to bugs labels Jan 18, 2025
@caiodelgadonew
Copy link
Author

Hi, @caiodelgadonew In the built-in docker template, we switched to a docker image resource to pull a pre-built image instead of building from the Dockerfile. This pre built image has a user with the name coder.

@phorcys420 can you take a look?

That makes a lot of sense, I was checking also the terraform providers for coder & docker and couldn't find anything related, codercom/enterprise-base and assumed on 2.17 was the same.

@phorcys420 phorcys420 self-assigned this Jan 18, 2025
@phorcys420
Copy link
Member

phorcys420 commented Jan 18, 2025

hey @caiodelgadonew, thanks for the heads-up.

The fact that the user is not being created is intended since we've switched to the generic coder user to avoid having to rebuild the image for every user.

See #15504 for the change that caused the issue, by switching from building a Dockerfile with a USER parameter to our enterprise-base image with the generic coder user, we kept persisting /home/<coder username> instead of the new /home/coder, so the persistent volume is not being created for the right folder.

I will be rolling out a fix soon, but in the meantime you can replace L198's contents by container_path = "/home/coder" in your template like this:

resource "docker_container" "workspace" {
  # [...]

  volumes {
-   container_path = "/home/${local.username}"
+   container_path = "/home/coder"
    volume_name    = docker_volume.home_volume.name
    read_only      = false
  }
}

@phorcys420 phorcys420 changed the title User doesn't get created by coder agent on docker containers starting on version v2.18 /home/coder volume is not being persisted on docker containers starting on version v2.18 Jan 18, 2025
@caiodelgadonew
Copy link
Author

@phorcys420 that fix on line 198 was what I did to fix it temporarily, not sure about the approach of the generic user, I personally like the idea of the username to match the container user

@phorcys420
Copy link
Member

@phorcys420 that fix on line 198 was what I did to fix it temporarily, not sure about the approach of the generic user, I personally like the idea of the username to match the container user

I agree that it feels more personalized but building the image in-template caused an anti-pattern and made things slower overall.

The issue with having a user created after the build time is that the tools are installed as the coder user in the image.
This causes:

  • Slow build times
  • Impossible to use cache for the layers coming after ARG USER because every command will depend on that specific username, which will also end up polluting the image storage

Now you could say that the coder user could then be renamed at runtime, and you'd be right, but the issue with this is that the software that's being installed in the image will likely still refer to /home/coder so you'd have to either create a symlink that points to /home/<username>, or do a find-and-replace, both approaches are hacky and will likely cause problems.

Another thing, how do you handle a user changing their username without running into the same problems?

All these are reasons that make it unsuitable for an example template, because it will cause issues if the template admin is unaware of it.
That said, you are free to edit the template to do this.

@caiodelgadonew
Copy link
Author

Gotcha @phorcys420 , all valid points.

I think your solution makes more sense.

Thanks!

phorcys420 added a commit that referenced this issue Jan 19, 2025
phorcys420 added a commit that referenced this issue Jan 19, 2025
…me/${local.user}` (#16190)

Backport of #16189, which is a fix for #16188
@matifali
Copy link
Member

Thanks, @caiodelgadonew, for reporting this. This is going to be live in the upcoming release 2.19 (4th of Feb.) and the 2.18.4 patch (Date to be decided).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
s2 Broken use cases or features (with a workaround). Only humans may set this.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants