简体   繁体   English

无法在 docker 容器中安装“sudo”

[英]Cannot install 'sudo' in docker container

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:我正在创建一个用于开发的 Docker 容器(我以前做过,从来没有遇到过这个问题)但是当 Dockerfile 执行命令“RUN apt-get install -y sudo”时,执行失败,结果如下:

#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:以下是我正在尝试运行的 dockerfile:

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

Try to Run only仅尝试运行

apt install sudo -y安装 sudo -y

Or Maybe you have to config or Check your:或者,也许您必须配置或检查您的:

Configuring Apt Sources / etc/apt/sources.list配置 Apt 源 /etc/apt/sources.list

Maybe you need to Install from contrib non-free sources not only from the main sources.也许您不仅需要从主要来源安装来自contrib 非免费来源。

Check this also: Debian SourcesList还要检查: Debian SourcesList

How to fix debian sudo command not found 如何修复 debian 找不到 sudo 命令

Edit your sources.list File add the non free package paths And/or run apt update than apt Install sudo again Fix the commands to your needs!编辑你的 sources.list 文件添加非自由 package 路径和/或运行 apt update 而不是 apt 再次安装 sudo 根据你的需要修复命令!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM