How to install brew into a Dockerfile (`brew: not found`)

Viewed 23

Rather than necro-post on a two-year old thread, I decided to create a new question.

I want add brew (homebrew) to a Docker container, but I get a brew: not found error.

The suggested solution in that previous article doesn't seem to work. This new Dockerfile...

FROM rust:1.63.0-buster
WORKDIR app

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

RUN brew install hello

gives this error... What am I missing? Thanks.

 => ERROR [6/6] RUN brew install hello                                                                   0.2s
------
 > [6/6] RUN brew install hello:
#9 0.181 /bin/sh: 1: brew: not found
------
executor failed running [/bin/sh -c brew install hello]: exit code: 127
1 Answers

This Dockerfile installs brew in /home/linuxbrew/.linuxbrew/bin/brew. Including that directory in the path (with the ENV command) does the trick.

...
ENV PATH="/home/linuxbrew/.linuxbrew/bin:${PATH}"
RUN brew install hello
Related