dockerubuntudockerfilesudoapt-get

ERROR: failed to solve: process "/bin/sh -c apt-get update"


I have the following Dockerfile where I want to build a Docker container from the image at https://hub.docker.com/r/julianassmann/opencv-cuda/:

FROM julianassmann/opencv-cuda 
#image name with OpenCV with CUDA

# Edit /etc/default/docker file to add custom DNS server
RUN echo 'DOCKER_OPTS="--dns 172.16.16.10"' >> /etc/default/docker

#working directory where i have placed container 
#on top of container
RUN apt-get update

RUN apt-get -y install sudo

# Install additional packages
RUN sudo apt update \
    #prevent interactive prompts
    && export DEBIAN_FRONTEND=noninteractive \
    && apt install -y lubuntu-desktop net-tools pip python3-tk \
    # Clean up no longer required by any other packages 
    && apt autoremove -y \
    #removes cached package files that were downloaded during the package installation
    && apt clean -y \
    #cached package lists and can be safely removed after installing packages
    && rm -rf /var/lib/apt/lists/* \
    #removes any files with names starting with reboot-required in the /run/ directory to prevent reboot after installing packages
    && rm /run/reboot-required*

# Create a non-root user with sudo priviledges
ARG USERNAME=user
ARG PASSWORD=password
ARG USER_UID=1000
ARG USER_GID=$USER_UID # Group ID (GID) of the user being created
#Creates a group with the specified USER_GID and name USERNAME
RUN groupadd --gid $USER_GID $USERNAME \
    #Creates a user with the specified USER_UID, USER_GID, USERNAME, and encrypted password generated from the PASSWORD. 
    #The -m flag ensures that a home directory is created for the user.
    #/bin/bash refers to the Bash shell executable binary file. Unix-like operating system,you specify the user's default shell
    && useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME -p $(openssl passwd $PASSWORD) \
    # [Optional] Add sudo support for the non-root user
    && apt update \
    && apt install -y sudo \
    #username allow execute commands as root without entering a password
    && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME\
    #Sets appropriate permissions
    && chmod 0440 /etc/sudoers.d/$USERNAME \
    # Clean up
    && apt autoremove -y \
    && apt clean -y \
    && rm -rf /var/lib/apt/lists/* \
    # provide auto-completion functionality when typing commands in the Bash shell
    && echo "source /usr/share/bash-completion/completions/git" >> /home/$USERNAME/.bashrc \
    # Configure remote desktop
    RUN adduser xrdp ssl-cert
RUN sed -i '3 a echo " \
    export GNOME_SHELL_SESSION_MODE=Lubuntu\\n\
    export XDG_SESSION_TYPE=x11\\n\
    export XDG_CURRENT_DESKTOP=LXQt\\n\
    export XDG_CONFIG_DIRS=/etc/xdg/xdg-Lubuntu:/etc/xdg\\n\
    " > ~/.xsessionrc' /etc/xrdp/startwm.sh
#default port used by Remote Desktop Protocol (RDP)
EXPOSE 3389

# Install Python dependencies
COPY requirements.txt .
RUN pip install --disable-pip-version-check --no-cache-dir -U -r requirements.txt \
    && rm requirements.txt

# Start xrdp and a bash terminal
CMD service xrdp start ; bash

I have the following error:

ERROR: failed to solve: process "/bin/sh -c apt-get update" did not complete successfully: exit code: 100

I don't understand the problem as I have installed sudo with the previous commands:

RUN apt-get update

RUN apt-get -y install sudo

Solution

  • I downloaded your Dockerfile and first error which you also stated is connected with apt-get update, it states that it can not find signatures (Public part of GPG keys) for nvidia packages.

    5.095 W: GPG error: https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64 InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY A4B469963BF863CC

    5.095 E: The repository 'https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64 InRelease' is not signed.

    I found the solution for this part on https://askubuntu.com/questions/1444943/nvidia-gpg-error-the-following-signatures-couldnt-be-verified-because-the-publi

    Fix is to add public keys before your apt-get update

    RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/3bf863cc.pub
    RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/7fa2af80.pub
    
    RUN apt-get update
    
    RUN apt-get -y install sudo
    

    Like so.

    When this step was done I tried rebuilding the image again, and then you have an error with installing pip on Ubuntu 18.

    On this line:

         && apt install -y lubuntu-desktop net-tools python3-pip python3-tk \
    

    2.876 Reading state information...

    2.937 E: Unable to locate package pip

    And the fix for this is found here:

    "E: Unable to locate package python-pip" on Ubuntu 18.04

    Which says you need to install python3-pip instead of just pip for the python3 dependency.

    Which makes it:

    && apt install -y lubuntu-desktop net-tools python3-pip python3-tk \
    

    The whole Dockerfile with these adjustments is:

    FROM julianassmann/opencv-cuda 
    #image name with OpenCV with CUDA
    
    # Edit /etc/default/docker file to add custom DNS server
    RUN echo 'DOCKER_OPTS="--dns 172.16.16.10"' >> /etc/default/docker
    
    #working directory where i have placed container 
    #on top of container
    
    RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/3bf863cc.pub
    RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/7fa2af80.pub
    
    RUN apt-get update
    
    RUN apt-get -y install sudo
    
    # Install additional packages
    RUN apt update \
        #prevent interactive prompts
        && export DEBIAN_FRONTEND=noninteractive \
        && apt install -y lubuntu-desktop net-tools python3-pip python3-tk \
        # Clean up no longer required by any other packages 
        && apt autoremove -y \
        #removes cached package files that were downloaded during the package installation
        && apt clean -y \
        #cached package lists and can be safely removed after installing packages
        && rm -rf /var/lib/apt/lists/* \
        #removes any files with names starting with reboot-required in the /run/ directory to prevent reboot after installing packages
        && rm /run/reboot-required*
    
    # Create a non-root user with sudo priviledges
    ARG USERNAME=user
    ARG PASSWORD=password
    ARG USER_UID=1000
    ARG USER_GID=$USER_UID # Group ID (GID) of the user being created
    #Creates a group with the specified USER_GID and name USERNAME
    RUN groupadd --gid $USER_GID $USERNAME \
        #Creates a user with the specified USER_UID, USER_GID, USERNAME, and encrypted password generated from the PASSWORD. 
        #The -m flag ensures that a home directory is created for the user.
        #/bin/bash refers to the Bash shell executable binary file. Unix-like operating system,you specify the user's default shell
        && useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME -p $(openssl passwd $PASSWORD) \
        # [Optional] Add sudo support for the non-root user
        && apt update \
        && apt install -y sudo \
        #username allow execute commands as root without entering a password
        && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME\
        #Sets appropriate permissions
        && chmod 0440 /etc/sudoers.d/$USERNAME \
        # Clean up
        && apt autoremove -y \
        && apt clean -y \
        && rm -rf /var/lib/apt/lists/* \
        # provide auto-completion functionality when typing commands in the Bash shell
        && echo "source /usr/share/bash-completion/completions/git" >> /home/$USERNAME/.bashrc \
        # Configure remote desktop
        RUN adduser xrdp ssl-cert
    RUN sed -i '3 a echo " \
        export GNOME_SHELL_SESSION_MODE=Lubuntu\\n\
        export XDG_SESSION_TYPE=x11\\n\
        export XDG_CURRENT_DESKTOP=LXQt\\n\
        export XDG_CONFIG_DIRS=/etc/xdg/xdg-Lubuntu:/etc/xdg\\n\
        " > ~/.xsessionrc' /etc/xrdp/startwm.sh
    #default port used by Remote Desktop Protocol (RDP)
    EXPOSE 3389
    
    # Install Python dependencies
    COPY requirements.txt .
    RUN pip install --disable-pip-version-check --no-cache-dir -U -r requirements.txt \
        && rm requirements.txt
    
    # Start xrdp and a bash terminal
    CMD service xrdp start ; bash
    

    NOTE:

    You still have one more error to solve:

    [ 9/11] RUN sed -i '3 a echo " export GNOME_SHELL_SESSION_MODE=Lubuntu\n export XDG_SESSION_TYPE=x11\n export XDG_CURRENT_DESKTOP=LXQt\n export XDG_CONFIG_DIRS=/etc/xdg/xdg-Lubuntu:/etc/xdg\n " > ~/.xsessionrc' /etc/xrdp/startwm.sh: 0.419 sed: can't read /etc/xrdp/startwm.sh: No such file or directory

    But I commented out this line from the Dockerfile, and it was built, Using the command docker image build -t cuda-test:0.0.1 .