.pyenv/shims not available as CLI arguments to docker run

66 Views Asked by At

I think I am missing something fundamental about how docker handles .pyenv shims. Executables that work without issues when a container is running interactively are suddenly not available when requested as a CLI argument to docker run.

For example,

$ docker pull gitpod/workspace-full     
# Get a cup of coffee
​
$ docker run -it --rm gitpod/workspace-full /bin/bash
# Now interactive inside a container...
​
gitpod ~ $ ls /home/gitpod/.pyenv/shims 
# Rejoice at the many shims displayed on your screen
​
gitpod ~ $ jupyter --version
Selected Jupyter core packages...
IPython          : 8.3.0
ipykernel        : 6.13.0
...etc...

gitpod ~ $ exit
# Now back at the host machine

$ docker run -it --rm gitpod/workspace-full /bin/bash -c "ls /home/gitpod/.pyenv/shims"
2to3      idle3    pip3    pydoc3    python3           python3.8-gdb.py
2to3-3.8  idle3.8  pip3.8  pydoc3.8  python3.8         python3-config
idle      pip      pydoc   python    python3.8-config  python-config
​
$ docker run -it --rm gitpod/workspace-full /bin/bash -c "jupyter --version"
/bin/bash: jupyter: command not found

What am I missing? This is obviously creating problems when attempting to autorun these executables via CMD.

Dockerfile

FROM gitpod/workspace-full

CMD ["/bin/bash", "-c", "jupyter --version"]

Building and running it two different ways:

$ docker build -t test .

$ docker run --rm test
/bin/bash: jupyter: command not found

$ docker run --rm -it test /bin/bash
gitpod ~ $ jupyter --version           # <--- Works

(If helpful, image source for gitpod containers can be found here: https://github.com/gitpod-io/workspace-images)

1

There are 1 best solutions below

0
On BEST ANSWER

I think you asked on our Discord server too. But posting here again in case it helps someone.

Instead of:

docker run -it --rm gitpod/workspace-full /bin/bash -c "jupyter --version"

do:

docker run -it --rm gitpod/workspace-full bash -ci "jupyter --version"

Why?

Python is being setup for the bash shell environment in interactive mode only as .bashrc file isn't loaded in non-interactive mode, so we pass -i to have the same effect.