Closed behrica closed 1 week ago
I had to remove the following lines from devcontainer.json to resolve the issue.
"args": {
"BASE_IMAGE": "${templateOption:imageTag}",
"USERNAME": "${localEnv:USER}"
}
Thanks for reporting
@marcitqualab I was never sure, whats the best approach for a generic setting of the container user is.
In my own devcontainer files, I did not touch it or tried to match it with the current user of the host. So it ended often being "vscode", the kind of default for most (all ?) devcontainer base images
I think we could write: ${localEnv:USER:VSCODE}
to make it default to VSCODE. @Netz00 , could you please try this for your case .
Now it also works, and the user inside the container is VSCODE.
"args": {
"USERNAME": "${localEnv:USER:VSCODE}"
}
I'm not sure why all these options and additional args
are used for the configuration, but great job!
First tme I used teh tmaplte I had a failing build of the image, due to localEnv:USER not set
Sorry I did not get notified about this issue until yesterday.
This is strange as the USERNAME is just an argument with default value as "vscode" is the docker file. https://github.com/scicloj/devcontainer-templates/blob/46b290418a7349bb4f83ed2bde619be148d7c6da/src/basecloj/.devcontainer/Dockerfile#L4 If you can provide more details of the error I might take a look.
Sorry I did not get notified about this issue until yesterday.
Sorry I did not get notified about this issue until yesterday.
Those lines are just optional as the docker file has default values for those arguments. The localEnv:USER should get the USER var env of the host machine. I think that the USER var env is generally available to all main linux distros. The line ""BASE_IMAGE": "${templateOption:imageTag}"," is there in case the user selects another base image while using the dev container wizard, at least in VScode. I am not sure how removing those lines will actually fix anything. If you can post some error logs I might be able to take a look.
Thanks for reporting
@marcitqualab I was never sure, whats the best approach for a generic setting of the container user is.
In my own devcontainer files, I did not touch it or tried to match it with the current user of the host. So it ended often being "vscode", the kind of default for most (all ?) devcontainer base images
The main point to run de dev container with your user home is to avoid permission issues. If the container runs as root or as another user the files created inside the container will not have the same user, owner and permissions as the user on the host machine. Therefore, you might get some issues while working. While using vscode as user name is just a default, and might not be major issues if the host machine user has another name. By default the docker file uses the user 'vscode', but the important thing is the user id that is set to the default '1000' like the default user on ubuntu. The base images used in this template come with a default non root user with id 1000. If the user with id 1000 does not exists in the docker image, then the only way that I have found so far is to create a new user in the docker file with the same user id as the user in the host machine. In summary, to avoid permission problems, the username is quite optional, but the user id needs to be the same in the host machine user an in the container user.
Now it also works, and the user inside the container is VSCODE.
"args": { "USERNAME": "${localEnv:USER:VSCODE}" }
I'm not sure why all these options and additional
args
are used for the configuration, but great job!
The docker file has already a 'vscode' value for the user name if the arg username is not provided. https://github.com/scicloj/devcontainer-templates/blob/46b290418a7349bb4f83ed2bde619be148d7c6da/src/basecloj/.devcontainer/Dockerfile#L4 I am not sure why or how this extra default value would help, but I would be interested to learn more about the issues that you get. Please share more log traces or fork this repo and share the link with us so we can reproduce the issues. Also provide more information about the host OS and your user name and id.
I was using Windows 10, which is why I removed it initially to make it work and ended up with the user from the Dockerfile, as expected: vscode. The extra value in ${localEnv:USER:VSCODE}
is a nice hack to support both OS.
${localEnv:USER:VSCODE}
retrieves theUSER
environment variable, and if theUSER
environment variable is not set or available, it falls back toVSCODE
instead of returningundefined
If you'd like, I can share the log traces, but I think it's resolved now.
I am aware of the initial Issue of Docker and user ids /permissions. But I was under the impression devcontainer solved it largely by default. It does some magic itself. But probably not in all cases.
Marc Andreu @.***> schrieb am Di., 10. Sept. 2024, 16:17:
Thanks for reporting
@marcitqualab https://github.com/marcitqualab I was never sure, whats the best approach for a generic setting of the container user is.
In my own devcontainer files, I did not touch it or tried to match it with the current user of the host. So it ended often being "vscode", the kind of default for most (all ?) devcontainer base images
The main point to run de dev container with your user home is to avoid permission issues. If the container runs as root or as another user the files created inside the container will not have the same user, owner and permissions as the user on the host machine. Therefore, you might get some issues while working. By default the docker file uses the user 'vscode', but the important thing is the user id that is set to the default '1000' like the default user on ubuntu. If you have permissions problems you might need to sync the user name and user id with your host user.
— Reply to this email directly, view it on GitHub https://github.com/scicloj/devcontainer-templates/issues/27#issuecomment-2340960429, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA7DAJCEFMXT7FWVETEDC3ZV35ONAVCNFSM6AAAAABJXUI4OSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNBQHE3DANBSHE . You are receiving this because you authored the thread.Message ID: @.***>
This commit should patch the Windows issue. The log traces show that the build failed after the following command tried to execute with an empty string value for the $USERNAME
variable.
https://github.com/scicloj/devcontainer-templates/blob/54b42e7c933092d1e20303a6ace74df2005c3336/src/basecloj/.devcontainer/Dockerfile#L9
Netz00/devcontainer-templates
Yes the commit looks ok, and I think that you need to create a PR against the scicloj repository so that the change could be merged to the main branch.
First tme I used teh tmaplte I had a failing build of the image, due to localEnv:USER not set
https://github.com/scicloj/devcontainer-templates/blob/46b290418a7349bb4f83ed2bde619be148d7c6da/src/basecloj/.devcontainer/devcontainer.json#L9