Skip to content

Commit 7da0520

Browse files
author
ide-coder
committed
fix: resolve tool accessibility issue caused by volume mount
- Move rbenv from /home/coder/.rbenv to /opt/rbenv (avoids volume mount overwrite) - Create symlinks for go/java commands in /usr/local/bin/ - Add /etc/profile.d/dev-tools.sh for system-wide PATH config - Fix .bashrc to use append (>>) instead of overwrite (>) This ensures go, java, ruby are accessible in VS Code terminal even when /home/coder is mounted from external volume.
1 parent cc7cab1 commit 7da0520

1 file changed

Lines changed: 34 additions & 14 deletions

File tree

Dockerfile

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ RUN go install golang.org/x/tools/gopls@latest \
5252
&& go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest \
5353
&& go install golang.org/x/tools/cmd/goimports@latest
5454

55+
# Create symlinks for go commands (ensures availability even when PATH is reset)
56+
RUN ln -s /usr/local/go/bin/go /usr/local/bin/go \
57+
&& ln -s /usr/local/go/bin/gofmt /usr/local/bin/gofmt
58+
5559
# Layer 4: Python + uv + conda with China mirrors
5660
ENV UV_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple
5761

@@ -107,8 +111,14 @@ RUN ARCH=$(dpkg --print-architecture) && \
107111
RUN curl -fsSL "https://archive.apache.org/dist/maven/maven-3/${MAVEN_VERSION}/binaries/apache-maven-${MAVEN_VERSION}-bin.tar.gz" | tar -C /opt -xzf - \
108112
&& ln -s /opt/apache-maven-${MAVEN_VERSION}/bin/mvn /usr/local/bin/mvn
109113

114+
# Create symlinks for java commands (ensures availability even when PATH is reset)
115+
RUN ln -s /opt/temurin-21-jdk/bin/java /usr/local/bin/java \
116+
&& ln -s /opt/temurin-21-jdk/bin/javac /usr/local/bin/javac \
117+
&& ln -s /opt/temurin-21-jdk/bin/jar /usr/local/bin/jar
118+
110119
# Layer 7: Ruby (rbenv) + Rails with Ruby China mirror
111-
ENV RBENV_ROOT=/home/coder/.rbenv
120+
# Install rbenv to /opt/rbenv to avoid being overwritten by volume mounts
121+
ENV RBENV_ROOT=/opt/rbenv
112122
ENV PATH=$RBENV_ROOT/bin:$RBENV_ROOT/shims:$PATH
113123

114124
# Install Ruby dependencies
@@ -126,23 +136,30 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
126136
libgdbm-dev \
127137
&& rm -rf /var/lib/apt/lists/*
128138

129-
# Install rbenv and ruby-build (as root, will be chown'd later)
130-
RUN git clone https://github.com/rbenv/rbenv.git /home/coder/.rbenv \
131-
&& git clone https://github.com/rbenv/ruby-build.git /home/coder/.rbenv/plugins/ruby-build
139+
# Install rbenv and ruby-build to /opt/rbenv (system path, not affected by volume mounts)
140+
RUN git clone https://github.com/rbenv/rbenv.git /opt/rbenv \
141+
&& git clone https://github.com/rbenv/ruby-build.git /opt/rbenv/plugins/ruby-build
132142

133143
# Install latest stable Ruby and Rails
134-
# Note: rbenv rehash generates shims in ~/.rbenv/shims directory
135-
RUN /home/coder/.rbenv/plugins/ruby-build/install.sh \
136-
&& RBENV_ROOT=/home/coder/.rbenv /home/coder/.rbenv/bin/rbenv install 3.4.1 \
137-
&& RBENV_ROOT=/home/coder/.rbenv /home/coder/.rbenv/bin/rbenv global 3.4.1 \
138-
&& RBENV_ROOT=/home/coder/.rbenv /home/coder/.rbenv/bin/rbenv rehash \
139-
&& RBENV_ROOT=/home/coder/.rbenv /home/coder/.rbenv/shims/gem install bundler rails --no-document \
140-
&& RBENV_ROOT=/home/coder/.rbenv /home/coder/.rbenv/bin/rbenv rehash
144+
RUN /opt/rbenv/plugins/ruby-build/install.sh \
145+
&& rbenv install 3.4.1 \
146+
&& rbenv global 3.4.1 \
147+
&& rbenv rehash \
148+
&& gem install bundler rails --no-document \
149+
&& rbenv rehash
141150

142151
# Configure gem mirror
143152
RUN echo "---\n:sources:\n - https://gems.ruby-china.com/" > /home/coder/.gemrc
144153

145154
# Layer 8: Directory structure and config files
155+
# Create system-wide PATH config (not affected by volume mounts on /home/coder)
156+
# This ensures tools are accessible in all shell types (login/non-login, interactive/non-interactive)
157+
RUN echo '#!/bin/sh\n\
158+
# Development tools PATH configuration\n\
159+
# Note: Symlinks in /usr/local/bin provide fallback, this is additional coverage\n\
160+
export PATH=/opt/rbenv/bin:/opt/rbenv/shims:/usr/local/go/bin:/home/coder/go/bin:/opt/temurin-21-jdk/bin:/opt/conda/bin:$PATH' > /etc/profile.d/dev-tools.sh \
161+
&& chmod +x /etc/profile.d/dev-tools.sh
162+
146163
# Create directories for external mounting support
147164
RUN mkdir -p /home/coder/project \
148165
&& mkdir -p /home/coder/.local/share/code-server \
@@ -184,13 +201,16 @@ RUN mkdir -p /home/coder/.npm
184201

185202
# Add PATH restoration and rbenv initialization to .bashrc
186203
# VS Code terminal is non-login shell, only .bashrc is read
187-
RUN echo '# Restore Docker ENV PATH (VS Code terminal resets PATH)\n\
188-
export PATH=/home/coder/.rbenv/bin:/home/coder/.rbenv/shims:/opt/temurin-21-jdk/bin:/opt/conda/bin:/usr/local/go/bin:/home/coder/go/bin:$PATH\n\
204+
# Use >> to append instead of > to avoid overwriting existing .bashrc
205+
RUN echo '\n\
206+
# Restore Docker ENV PATH (VS Code terminal resets PATH)\n\
207+
export PATH=/opt/rbenv/bin:/opt/rbenv/shims:/opt/temurin-21-jdk/bin:/opt/conda/bin:/usr/local/go/bin:/home/coder/go/bin:$PATH\n\
189208
\n\
190209
# Initialize rbenv\n\
191-
eval "$(/home/coder/.rbenv/bin/rbenv init - bash)"' > /home/coder/.bashrc
210+
eval "$(/opt/rbenv/bin/rbenv init - bash)"' >> /home/coder/.bashrc
192211

193212
# Set ownership for coder user
213+
# Note: /opt/rbenv is owned by root, but accessible by all users
194214
RUN chown -R coder:coder /home/coder \
195215
&& chown -R coder:coder /opt/conda
196216

0 commit comments

Comments
 (0)