在 Docker 构建期间安装 brew 包不起作用

时间:2021-02-04 06:06:53

标签: docker dockerfile homebrew

我正在尝试在 docker 构建期间使用以下 dockerfile 安装 arduino-cli(一个自制程序包)。

docker 映像似乎构建正确,但是在我的 Web 服务器上运行时,我在日志中得到以下输出。

请注意,此问题似乎与 Installing homebrew packages during Docker build 类似,但已接受的答案似乎对我没有帮助。

这是否表明 arduino-cli 没有正确安装,或者只是路径没有正确链接?

FileNotFoundError: [Errno 2] No such file or directory: 'arduino-cli': 'arduino-cli'
FROM python:3.6

RUN apt-get update && apt-get install -y git curl binutils clang make
RUN git clone https://github.com/Homebrew/brew ~/.linuxbrew/Homebrew \
&& mkdir ~/.linuxbrew/bin \
&& ln -s ../Homebrew/bin/brew ~/.linuxbrew/bin \
&& eval $(~/.linuxbrew/bin/brew shellenv) \
&& brew --version \
&& brew install arduino-cli \
&& arduino-cli version
ENV PATH=~/.linuxbrew/bin:~/.linuxbrew/sbin:$PATH

RUN mkdir -p /opt/services/djangoapp/src
WORKDIR /opt/services/djangoapp/src

RUN pip install gunicorn django psycopg2-binary whitenoise

COPY . /opt/services/djangoapp/src

EXPOSE 8000

COPY init.sh /usr/local/bin/
    
RUN chmod u+x /usr/local/bin/init.sh
ENTRYPOINT ["init.sh"]

2 个答案:

答案 0 :(得分:0)

很可能是 $PATH 问题。提到的答案对您不起作用的原因是您在 $PATH 尚未更改时尝试使用 arduino-cli。这应该使它起作用:

RUN git clone https://github.com/Homebrew/brew ~/.linuxbrew/Homebrew \
&& mkdir ~/.linuxbrew/bin \
&& ln -s ../Homebrew/bin/brew ~/.linuxbrew/bin \
&& eval $(~/.linuxbrew/bin/brew shellenv) \
&& brew --version \
&& brew install arduino-cli

# first change PATH
ENV PATH=~/.linuxbrew/bin:~/.linuxbrew/sbin:$PATH

# then run
RUN arduino-cli version

# not vice-versa

答案 1 :(得分:0)

这听起来可能很疯狂,但我是否建议为此使用 [多阶段 dockerfile][1]。这将消除容器上的残留物并减少安全访问点。

FROM homebrew/brew:latest AS brew
RUN brew update
RUN brew install arduino-cli

# RUN brew list ardunio-cli
FROM python:3.6
COPY --from=brew /usr/local/Cellar /user/local

ENV PATH=~/.linuxbrew/bin:~/.linuxbrew/sbin:$PATH

RUN mkdir -p /opt/services/djangoapp/src
WORKDIR /opt/services/djangoapp/src

RUN pip install gunicorn django psycopg2-binary whitenoise

COPY . /opt/services/djangoapp/src

EXPOSE 8000

COPY init.sh /usr/local/bin/
    
RUN chmod u+x /usr/local/bin/init.sh
ENTRYPOINT ["init.sh"]

可能需要制作一些额外的符号来使 brew 文件正常工作,但您的最终容器将更加小巧且使用起来更安全。