0

I'm creating a Docker container for development (I've done it before and never had this problem) but when the Dockerfile executes the command ''RUN apt-get install -y sudo" the execution fails with the following result:

#0 0.563 Reading package lists...
#0 0.594 Building dependency tree...
#0 0.602 Reading state information...
#0 0.607 Package sudo is not available, but is referred to by another package.
#0 0.607 This may mean that the package is missing, has been obsoleted, or
#0 0.607 is only available from another source
#0 0.607
#0 0.609 E: Package 'sudo' has no installation candidate

The following is the dockerfile I'm trying to run:

FROM node:18-bullseye

# Arguments
ARG USER=platzi
ARG USER_HOME=/home/$USER
ARG VOLUME=/home/volume
ARG SHELL=/bin/bash

RUN apt-get update

# Install OS utilities
RUN apt-get install -y locales \
    && sed -i 's/^# *\(en_US.UTF-8\)/\1/' /etc/locale.gen \
    && locale-gen
RUN apt-get install -y sudo   **execution fails here**
RUN apt-get install -y python3-pip
RUN pip3 install --upgrade pip

# Install Dev utilities
RUN pip3 install yapf
RUN pip3 install jupyter

# Install CLI utilities
RUN apt-get install -y jq
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" \
    && unzip awscliv2.zip \
    && ./aws/install \
    && apt-get install -y less

# Set up non root user
RUN echo "$USER ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
RUN useradd -ms $SHELL $USER
RUN mkdir -p $VOLUME \
    && chown -R $USER:$USER $VOLUME

# Preserve bash history
RUN SNIPPET="export PROMPT_COMMAND='history -a' && export HISTFILE=/commandhistory/.bash_history" \
    && echo $SNIPPET >> "/root/.bashrc" \
    && mkdir /commandhistory \
    && touch /commandhistory/.bash_history \
    && chown -R $USER /commandhistory \
    && echo $SNIPPET >> "$USER_HOME/.bashrc"

USER $USER
  • You usually need to `RUN apt-get update && apt-get install` in a single `RUN` line; also see [Cannot install packages inside docker Ubuntu image](https://stackoverflow.com/questions/27273412/cannot-install-packages-inside-docker-ubuntu-image). Usually in Docker you don't need `sudo` at all since it's hard to make secure (the setup you show here gives your "non-root" user unlimited permission so long as they ask politely) and an operator can always `docker run -u root` if they need a container as root. – David Maze Jan 09 '23 at 14:11

0 Answers0