如何在Docker容器内的Ubuntu上安装自制程序

v7pvogib  于 2022-11-02  发布在  Docker
关注(0)|答案(3)|浏览(185)

当我尝试在Ubuntu 18.04上安装自制软件时


# Dockerfile

FROM ubuntu:18.04

RUN apt-get update && apt-get install build-essential curl file git -y
RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)"

获取错误:
==〉通过运行以下命令将Ruby添加到PATH中:请不要以root用户身份运行这个程序!

gmxoilav

gmxoilav1#

您不能使用official imagedocker pull linuxbrew/linuxbrew)有什么原因吗?它基于Ubuntu 16.04 / Xenial。
如果你必须使用Bionic(18.04),正确的安装方法是按照官方Dockerfile中的步骤进行。
但是要使您的Dockerfile工作,您需要安装ruby,创建一个非root用户,并以该用户的身份执行安装脚本。

FROM ubuntu:18.04

RUN apt-get update && \
    apt-get install build-essential curl file git ruby-full locales --no-install-recommends -y && \
    rm -rf /var/lib/apt/lists/*

RUN localedef -i en_US -f UTF-8 en_US.UTF-8

RUN useradd -m -s /bin/bash linuxbrew && \
    echo 'linuxbrew ALL=(ALL) NOPASSWD:ALL' >>/etc/sudoers

USER linuxbrew
RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)"

USER root
ENV PATH="/home/linuxbrew/.linuxbrew/bin:${PATH}"

PS:我添加了--no-install-recommends来忽略可选的依赖项,添加了rm -rf /var/lib/apt/lists/*来删除apt-get的剩余项,从而减少映像大小。另外,添加了locales来安装UTF-8,否则brew会在运行命令时抛出警告。

deyfvvtc

deyfvvtc2#

新的正确方式是:

RUN apt-get update && \
    apt-get install -y -q --allow-unauthenticated \
    git \
    sudo
RUN useradd -m -s /bin/zsh linuxbrew && \
    usermod -aG sudo linuxbrew &&  \
    mkdir -p /home/linuxbrew/.linuxbrew && \
    chown -R linuxbrew: /home/linuxbrew/.linuxbrew
USER linuxbrew
RUN /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
bq9c1y66

bq9c1y663#

Gabriel的回答对我来说基本上是有效的,但是缺少了一个步骤。我需要将chown文件夹/home/linuxbrew/.linuxbrew给运行Homebrew的用户:

RUN apt-get update && \
    apt-get install -y -q --allow-unauthenticated \
    git \
    sudo
RUN useradd -m -s /bin/zsh linuxbrew && \
    usermod -aG sudo linuxbrew &&  \
    mkdir -p /home/linuxbrew/.linuxbrew && \
    chown -R linuxbrew: /home/linuxbrew/.linuxbrew
USER linuxbrew
RUN /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

USER root
RUN chown -R $CONTAINER_USER: /home/linuxbrew/.linuxbrew

相关问题