Skip to content
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

PATH environment variable not set on initial terminal #1585

Closed
n-i-x opened this issue May 1, 2020 · 8 comments
Closed

PATH environment variable not set on initial terminal #1585

n-i-x opened this issue May 1, 2020 · 8 comments
Labels
waiting-for-info Waiting for more information from submitter

Comments

@n-i-x
Copy link

n-i-x commented May 1, 2020

I can't really test this on VSCode so I haven't done that.

I'm running code-server in a docker container and have exported PATH to include /usr/local/go/bin in the path. When loading the app, the initial terminal window does not have the PATH set. Any additional terminals have the path set properly. Opening a new Chrome tab and launching code-server has the same behavior.

To replicate my setup, you can use:

docker create
--name=code-server
-e PUID=1000
-e PGID=1000
-e TZ=America/New_York
-e DOCKER_MODS=linuxserver/mods:code-server-python3|nixapps/codeserver-golang:latest
-p 8443:8443
-v /path/to/appdata/config:/config
--restart unless-stopped
linuxserver/code-server

You'll notice /usr/local/go/bin is not in the path at first but it will be if you open up another terminal.

@Grimeton
Copy link

Grimeton commented May 1, 2020

Hi,

the environment is either inherited by the CodeServer's environment or not. If the first terminal does not have the PATH but the following ones do, something else is wrong.

Check how the first shell gets started and how the others are. If there's a difference there's a high chance that the PATH modification inside .bash_login, .bashrc, whatever is ignored because the shell is not a login or an interactive shell.

Cu

@jrebey
Copy link

jrebey commented May 1, 2020

I'm not setting PATH in a shell env file like .bash_login, .bashrc, etc. (which only works with bash and would be ignored by the default sh or another shell). I'm exporting it in the environment before running code-server.

@nhooyr
Copy link
Contributor

nhooyr commented May 18, 2020

Why are you using linuxserver/code-server? Does this occur on our docker image as well? codercom/code-server.

@nhooyr nhooyr added the waiting-for-info Waiting for more information from submitter label May 18, 2020
@nhooyr
Copy link
Contributor

nhooyr commented May 27, 2020

I'm exporting it in the environment before running code-server.

Are you directing Docker to pass it in with -e?

@nhooyr
Copy link
Contributor

nhooyr commented May 27, 2020

Oh sorry replied to wrong person.

Closing for lack of activity and no one else can reproduce.

@nhooyr nhooyr closed this as completed May 27, 2020
@mwaeckerlin
Copy link

mwaeckerlin commented Nov 17, 2023

I have the same problem, this is my Dockerfile:

FROM mwaeckerlin/dockindock AS docker

FROM mwaeckerlin/nodejs-build AS build
ENV BUILD_PKGS "alpine-sdk bash libstdc++ libc6-compat npm python3 krb5-pkinit krb5-dev krb5 shadow"
ENV HOME /code
ENV FORCE_NODE_VERSION false
COPY --from=docker / /
USER root
RUN $PKG_INSTALL $BUILD_PKGS
RUN npm install -g code-server --unsafe-perm
RUN usermod -d ${HOME} ${RUN_USER}
RUN ${ALLOW_USER} ${HOME}
RUN rm -rf /app /home
COPY .profile ${HOME}/
ENV RUN_PKGS "git openssh rootlesskit"
RUN $PKG_INSTALL $RUN_PKGS

FROM mwaeckerlin/dockindock
ENV CONTAINERNAME "vscode"
ENV SHELL "/bin/bash"
ENV HOME "/code"
ENV XDG_RUNTIME_DIR "/docker"
ENV PATH "${XDG_RUNTIME_DIR}/bin:$PATH"
ENV DOCKER_HOST "unix://${XDG_RUNTIME_DIR}/docker.sock"
COPY --from=build / /
CMD HOME=${XDG_RUNTIME_DIR} ${XDG_RUNTIME_DIR}/bin/dockerd-rootless.sh & \
    /usr/local/bin/code-server --bind-addr 0.0.0.0:${PORT:-8080} \
                               --config ${HOME}/.config/config.yaml \
                               --user-data-dir ${HOME}/.config
WORKDIR ${HOME}
VOLUME ${HOME}
EXPOSE 8080

As you see, PATH is set in the environment before code-server is started.

Then in the vscode terminal:

7ad6627f896f:~$ echo $PATH
/usr/local/lib/node_modules/code-server/lib/vscode/bin/remote-cli:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
7ad6627f896f:~$ echo "${XDG_RUNTIME_DIR}/bin:$PATH"
/docker/bin:/usr/local/lib/node_modules/code-server/lib/vscode/bin/remote-cli:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

As you can see, ${XDG_RUNTIME_DIR}/bin, which resolves to /docker/bin is missing in my PATH!

Same problem with PS1, which is overwritten by code-server, and I cannot set it.

Also neither .profile nor .bashrc are executed; or at least variables set there are ignored.

@code-asher
Copy link
Member

code-asher commented Nov 17, 2023

Are you sure files like .profile and .bashrc are not being read? If PATH or PS1 is being set in one of these files (or something like /etc/profile maybe) then they would overwrite the existing values, I think.

@code-asher
Copy link
Member

code-asher commented Nov 17, 2023

Ah yup check this out:

$ docker run --rm -it mwaeckerlin/dockindock sh  
somebody@dockindock[57da347e5db7]:~$ head -n 1 /etc/profile
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

It sets PS1 too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting-for-info Waiting for more information from submitter
Projects
None yet
Development

No branches or pull requests

6 participants