0

I'm trying to learn docker. This is my first experiment. I have written this dockerfile :

FROM nvidia/cudagl:11.3.0-base-ubuntu20.04

LABEL Author="ZioMario"
LABEL Title="Firefox/Docker20.10.6/Ubuntu20.04"

# Enviorment variables

ENV DEBIAN_FRONTEND noninteractive
ENV LC_ALL C.UTF-8
ENV LANG C.UTF-8
ENV PATH "$PATH:/bin/2.82/python/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
ENV FIREFOX_PATH "/bin/2.82"
ENV FIREFOXPIP "/bin/2.82/python/bin/pip3"
ENV FIREFOXPY "/bin/2.82/python/bin/python3.7m"
ENV HW="GPU"

# Install dependencies

RUN apt-get update && apt-get install -y \ 
    apt-utils \
    wget \ 
    libopenexr-dev \ 
    bzip2 \ 
    build-essential \ 
    zlib1g-dev \ 
    libxmu-dev \ 
    libxi-dev \ 
    libxxf86vm-dev \ 
    libfontconfig1 \ 
    libxrender1 \ 
    libgl1-mesa-glx \ 
    xz-utils \
    firefox \
    openjdk-8-jre

# Download the Python source

RUN wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz \ 
    && tar -xzf Python-3.7.0.tgz \ 
    && cp -r Python-3.7.0/Include/* $FIREFOX_PATH/python/include/python3.7m/ \ 
    && rm -rf Python-3.7.0.tgz \ 
    && rm -rf Python-3.7.0 

# Installing a modern version of numpy

RUN rm -rf ${FIREFOX_PATH}/python/lib/python3.7/site-packages/numpy 

# Must first ensurepip to install Firefox pip3 and then new numpy

RUN ${FIREFOXPY} -m venv protected-env

RUN source protected-env/bin/activate

RUN ${FIREFOXPY} -m ensurepip && ${FIREFOXPIP} install --upgrade pip && ${FIREFOXPIP} install numpy
RUN deactivate

# Set the working directory
WORKDIR /

Unfortunately it does not work. This is the error that I'm getting :

The command '/bin/sh -c source protected-env/bin/activate' returned a non-zero code: 127

the wrong line is this :

RUN source protected-env/bin/activate

Do you have any idea about how to fix it ? thanks.

3
  • You tagged this bash, however as you can see from the error message, docker RUN is using /bin/sh - which does not recognize the source command May 3, 2021 at 14:39
  • 1
    Besides, I think each RUN creates its own shell process. If I am right, whatever you source is only valid in that process and does not affect the other RUNs. May 3, 2021 at 14:45
  • Crossposted here: askubuntu.com/questions/1335797/… May 3, 2021 at 15:22

1 Answer 1

0
RUN source protected-env/bin/activate

makes no sense.

activate is a script that sets a few environment variables for the current shell; however, the current shell dies directl after sourcing that file. So, it has no effect. Especially, it has no effect on the next line!

Your error, however, stems from the fact that you're trying to run a bash script with sh, which doesn't work. Solution here is to put all these things (sourceing the activate file, installing things using pip) into a single shell script that starts with #!/bin/bash, so that it can be executed in one go, and then COPYing it into your container image, then RUNning that.

However, I've not yet encountered a reason to install numpy via pip. You should probably not do that, but install it using apt!

Same, and even more so, applies to python itself. Don't build that from source – I don't know where your guide is from, but seriously, that's a terrible idea. Your ubuntu comes with Python3, most probably even preinstalled, or installable as apt install python3, done! In total, you'd just add python3-numpy to the end of your list of packages to install, and be done; no downloading python, no building it, and certainly no need to source some activate file and install numpy via pip!

9
  • I've read here : pythonspeed.com/articles/activate-virtualenv-dockerfile I'm not sure that it works...not tried yet ENV VIRTUAL_ENV=/protected-env ENV PATH "$PATH:"$VIRTUAL_ENV:/bin:/bin/2.82/python/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin" RUN ${FIREFOXPY} -m venv $VIRTUAL_ENV Installing a modern version of numpy RUN rm -rf ${FIREFOX_PATH}/python/lib/python3.7/site-packages/numpy RUN ${FIREFOXPY} -m ensurepip && ${FIREFOXPIP} install --upgrade pip && ${FIREFOXPIP} install numpy
    – Marietto
    May 3, 2021 at 15:50
  • as said, multiple times, in my answer: you don't need any of that virtualenv stuff. really. stop trying to solve problems that you only have because you've found guides online that you're not understanding. I literally wrote what you need to do (add python3-numpy to your list of packages that you install using apt, remove all the rest of your dockerfile, since its senseless) May 3, 2021 at 16:28
  • without virtual env I get this warning : WARNING: Running pip as root will break packages and permissions. You should install packages reliably by using venv: pip.pypa.io/warnings/venv
    – Marietto
    May 3, 2021 at 17:44
  • ... you still didn't read what I wrote. You don't need to run pip at all. You should not run pip at all. May 3, 2021 at 19:54
  • Do you like to get shortcuts. Me too,sometimes. Most frequently I want to solve problems directly.
    – Marietto
    May 3, 2021 at 20:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .