如何在Docker容器内的Ubuntu上安装自制软件

时间:2019-10-08 19:27:43

标签: docker ubuntu homebrew

当我尝试在Ubuntu 18.04上进行install自酿

# 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:PATH = / root / .linuxbrew / Homebrew / Library / Homebrew / vendor / portable-ruby / current / bin:$ PATH   不要以超级用户身份运行它!

3 个答案:

答案 0 :(得分:2)

是否有不能使用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会发出警告。

答案 1 :(得分:2)

新的正确方法是:

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)"

答案 2 :(得分:2)

Gabriel的回答大部分对我有用,但缺少一步。我需要将chown文件夹/home/linuxbrew/.linuxbrew运到将要运行Homebrew的用户:

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