Skip to content

Commit 4e1b159

Browse files
committed
Workaround Docker remoteUser permissions
1 parent 8c07b81 commit 4e1b159

File tree

3 files changed

+44
-6
lines changed

3 files changed

+44
-6
lines changed

templates/Dockerfile

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,24 @@
66
#
77
FROM public.ecr.aws/lambda/nodejs:{{nodeVersion}}
88

9-
RUN dnf install -y gzip tar
9+
ARG BASE_DIR
10+
ARG USER
11+
ARG GROUP=${USER}
12+
ARG UID
13+
ARG GID=${UID}
14+
15+
RUN dnf -y install gcc git gzip libyaml-devel make shadow-utils tar
16+
17+
# Install app dependencies.
18+
RUN npm install -g pm2
19+
20+
ENV PATH="${PATH}:/usr/sbin"
21+
22+
# Create shared workspace.
23+
RUN groupadd -g ${UID} ${USER}
24+
RUN useradd -u ${UID} -g ${GID} -G root -s /usr/bin/bash -m ${USER}
25+
RUN chown ${USER}:${GROUP} ${BASE_DIR}
26+
27+
USER ${USER}
28+
29+
WORKDIR ${BASE_DIR}

templates/README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,19 @@ Generate documentation using [JSDoc](https://jsdoc.app):
5959

6060
## Known issues
6161

62-
### Project files are assigned root priviledges
62+
### Project files are assigned incorrect priviledges
6363

64-
This is due to a [bug](https://github.com/microsoft/vscode-remote-release/issues/2402) in the [Remote Container](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension, not this project. During the container build process when the local machines's UID/GID matches an existing user UID/GID in the container it assigns `root` by default. Note, in normal circumstances the [`remoteUser`](https://containers.dev/implementors/json_reference/#remoteUser) assigned would be `vscode` which always matches the local machine's user UID/GID values.
64+
If you experience this when working between local/remote development environments this is due to the user UID [not being present during build time](https://github.com/microsoft/vscode-remote-release/issues/6834#issuecomment-1158600543). In this case the default `1000` is defined as both the UID/GID for the remote user. You can override this behavior by updating the following project `devcontainer.json` build arguments or by exporting the UID/GID in your `.bash_profile`.
65+
66+
```json
67+
"build": {
68+
"dockerfile": "Dockerfile",
69+
"args": {
70+
"UID": "${localEnv:UID:1234}", // Default to 1234
71+
"GID": "${localEnv:GID:1234}"
72+
}
73+
},
74+
```
6575

6676
## References
6777

templates/devcontainer.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
{
22
"name": "{{appName}}",
3-
"build": {"dockerfile": "Dockerfile"},
3+
"build": {
4+
"dockerfile": "Dockerfile",
5+
"args": {
6+
"BASE_DIR": "/var/task",
7+
"USER": "${localEnv:USER}",
8+
"UID": "${localEnv:UID:1000}"
9+
//"GROUP": "${localEnv:USER}",
10+
//"GID": "${localEnv:GID:1000}",
11+
}
12+
},
413
"forwardPorts": [3000],
514
// Mounting AWS config (Requires container rebuild)
615
//"mounts": ["source=${localEnv:HOME}/.aws,target=/root/.aws,type=bind,consistency=cached"],
7-
"workspaceMount": "source=${localWorkspaceFolder},target=/var/task,type=bind",
816
"workspaceFolder": "/var/task",
17+
"workspaceMount": "source=${localWorkspaceFolder},target=/var/task,type=bind",
918
"containerEnv": {
1019
"LAMBDA_TASK_ROOT": "${containerWorkspaceFolder}/{{appName}}/src"
1120
},
1221
"updateContentCommand": "npm install --prefix ${containerWorkspaceFolder}/{{appName}} >/dev/null",
13-
"postCreateCommand": "npm install -g pm2",
1422
"postStartCommand": "pm2 start ${containerWorkspaceFolder}/.devcontainer/ecosystem.config.js",
1523
"customizations": {
1624
"vscode": {

0 commit comments

Comments
 (0)