Why does PATH differ when I connect to my Docker container with ssh or with exec/attach?

Published

I build a Docker image based on the following Dockerfile:

ARG PYTORCH="1.6.0"
ARG CUDA="10.1"
ARG CUDNN="7"

FROM pytorch/pytorch:${PYTORCH}-cuda${CUDA}-cudnn${CUDNN}-devel

ENV TORCH_CUDA_ARCH_LIST="6.0 6.1 7.0+PTX"
ENV TORCH_NVCC_FLAGS="-Xfatbin -compress-all"
ENV CMAKE_PREFIX_PATH="$(dirname $(which conda))/../"

# SSH SERVER
RUN apt-get update && apt-get install openssh-server sudo -y
RUN echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
RUN echo 'root:root' | chpasswd

WORKDIR /

EXPOSE 22
CMD ["service ssh start"]

(if the Dockerfile seems weird to you, feel free to have a look at my other question How can I start my PyTorch-based Docker container with a ssh server, and keep it alive?)

I launch the Docker container with

docker run -it -d -p 7220:22 --name ssh-server-test ssh-server-image /bin/bash

If I connect to the container with docker exec -it ssh-server-test /bin/bash or docker attach ssh-server-test, I get the PATH I expect:

[email protected]:/# echo $PATH
/opt/conda/bin:/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

However, if I start an ssh server with

[email protected]:/# service ssh start
 * Starting OpenBSD Secure Shell server sshd                                                                                                                                [ OK ] 
[email protected]:/# 

and I connect to the Docker container through ssh as root, then the PATH is completely different!

[email protected]:~# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

Why? And how can I get the right PATH variable also when I connect to the container through ssh?

Source: Docker Questions

Published
Categorised as docker, environment-variables, pytorch, server, ssh Tagged , , , ,

Answers

Leave a Reply

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq