1

我正在尝试asdf-direnv在docker中使用。按照自述文件,asdf-direnv我制作了这个 Dockerfile

FROM nvidia/cuda:10.2-devel-ubuntu18.04

RUN chsh -s /bin/bash
SHELL ["/bin/bash", "-ic", "-l"]

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update
    # Python
RUN apt-get install -y make build-essential libssl-dev zlib1g-dev \
    libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \
    libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
    # Utils
RUN apt-get install -y git
RUN apt-get clean

WORKDIR /venv

RUN git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.8.1
RUN echo ". $HOME/.asdf/asdf.sh" >> ~/.bashrc
RUN echo ". $HOME/.asdf/completions/asdf.bash" >> ~/.bashrc

RUN asdf plugin add direnv
RUN asdf install direnv 2.28.0
RUN asdf local direnv 2.28.0
RUN echo "eval \"\$(asdf exec direnv hook bash)\"" >> ~/.bashrc
RUN echo "direnv() { asdf exec direnv \"\$@\"; }" >> ~/.bashrc

RUN mkdir -p ~/.config/direnv/
RUN echo "source \"\$(asdf direnv hook asdf)\"" >> ~/.config/direnv/direnvrc
RUN echo "export DIRENV_LOG_FORMAT=" >> ~/.config/direnv/direnvrc

RUN asdf plugin add python
RUN asdf install python 3.8.7
RUN asdf local python 3.8.7

RUN echo "use asdf" >> .envrc
RUN echo "layout python" >> .envrc
RUN direnv allow
RUN echo $(which python)

CMD ["/bin/bash"]

问题是,这条线RUN echo $(which python)在我运行时可以正常工作,但在我构建映像时却不行。我有

  • /root/.asdf/shims/python建的时候docker build . -t venv-gpu -f docker-gpu/Dockerfile
  • /venv/.direnv/python-3.8.7/bin/python什么时候docker run --gpus all -it venv-gpu

我该如何解决这个问题?

4

0 回答 0