Skip to content

Commit 17b0c26

Browse files
committed
chore: enable host to specify docker group id
1 parent 6ac39f0 commit 17b0c26

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

.devcontainer/Dockerfile

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
11
FROM mcr.microsoft.com/devcontainers/base:ubuntu
22

3-
ARG TARGETARCH
4-
ENV TARGETARCH=${TARGETARCH}
3+
# provide DOCKER_GID via build args if you need to force group id to match host
4+
ARG DOCKER_GID
5+
6+
# specify DOCKER_GID to force container docker group id to match host
7+
RUN if [ -n "${DOCKER_GID}" ]; then \
8+
if ! getent group docker; then \
9+
groupadd -g ${DOCKER_GID} docker; \
10+
else \
11+
groupmod -g ${DOCKER_GID} docker; \
12+
fi && \
13+
usermod -aG docker vscode; \
14+
fi
515

616
ARG ASDF_VERSION
717
COPY .tool-versions.asdf /tmp/.tool-versions.asdf
818

19+
ARG TARGETARCH
20+
ENV TARGETARCH=${TARGETARCH}
21+
922
# Add amd64 architecture if on arm64
1023
RUN if [ "$TARGETARCH" = "arm64" ] || [ "$TARGETARCH" = "aarch64" ]; then dpkg --add-architecture amd64; fi
1124

25+
# Anticipate and resolve potential permission issues with apt
26+
RUN mkdir -p /tmp && chmod 1777 /tmp
27+
1228
RUN apt-get update \
1329
&& export DEBIAN_FRONTEND=noninteractive \
1430
&& apt-get -y dist-upgrade \
@@ -51,7 +67,6 @@ RUN ASDF_VERSION=$(awk '!/^#/ && NF {print $1; exit}' /tmp/.tool-versions.asdf)
5167
tar -xvzf /tmp/asdf.tar.gz && \
5268
mv asdf /usr/bin
5369

54-
5570
USER vscode
5671

5772
ENV PATH="/home/vscode/.asdf/shims/:$PATH"

.devcontainer/devcontainer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
"build": {
77
"dockerfile": "Dockerfile",
88
"context": "..",
9-
"args": {}
9+
"args": {
10+
"DOCKER_GID": "${env:DOCKER_GID:}"
11+
}
1012
},
1113
"mounts": [
1214
"source=${env:HOME}${env:USERPROFILE}/.aws,target=/home/vscode/.aws,type=bind",

0 commit comments

Comments
 (0)