bazel: Bazel fails to run inside Docker container

Running bazel inside of a Docker container fails to make any progress terminating “previous” processes when executed from a Bazel workspace. This happens even after running bazel shutdown before trying to execute bazel from within the Docker container. Below is an example of Bazel’s output and the corresponding Dockerfile.

working command (not ran from Bazel workspace)

$ docker run --rm -ti bazel
Extracting Bazel installation...
Apr 17, 2015 5:31:46 PM com.google.devtools.build.lib.runtime.BlazeRuntime batchMain
INFO: Running Blaze in batch mode with startup args [--batch, --install_base=/root/.cache/bazel/_bazel_root/install/f05fefbab57bb043124ff4a4a441b0be, --output_base=/root/.cache/bazel/_bazel_root/d41d8cd98f00b204e9800998ecf8427e, --workspace_directory=, --nofatal_event_bus_exceptions, --option_sources=]
                                                     [bazel development version]
Usage: bazel <command> <options> ...

running bazel from within Bazel workspace ($HOME/repo)

$ cd $HOME/repo
$ bazel shutdown
..........
$ docker run --rm -ti -v "$PWD:/repo" -w /repo bazel
Extracting Bazel installation...
.....
Sending SIGTERM to previous Bazel server (pid=29)... done.
......
Sending SIGTERM to previous Bazel server (pid=79)... done.
.....
Sending SIGTERM to previous Bazel server (pid=129)... done.
.....
Sending SIGTERM to previous Bazel server (pid=179)... done.
.....
Sending SIGTERM to previous Bazel server (pid=229)... done.
.....
Sending SIGTERM to previous Bazel server (pid=279)... done.
.....
Sending SIGTERM to previous Bazel server (pid=329)... done.
.....
Sending SIGTERM to previous Bazel server (pid=379)... done.
....^C

Dockerfile

# docker build -t bazel .                                                                                                                                      
FROM debian:jessie                                                                                                                                             

ENV DEBIAN_FRONTEND noninteractive                                                                                                                             

RUN apt-get update && \                                                                                                                                        
    apt-get upgrade -y && \                                                                                                                                    
    apt-get install -y --no-install-recommends curl ca-certificates && \                                                                                       
    apt-get clean                                                                                                                                              

RUN curl https://storage.googleapis.com/dev-con-jessie-apt/convoy.key | apt-key add -                                                                          
RUN echo deb http://storage.googleapis.com/dev-con-jessie-apt/ jessie main >> /etc/apt/sources.list                                                            

RUN apt-get update && \                                                                                                                                        
    apt-get install -y --no-install-recommends \                                                                                                               
      git pkg-config zip unzip \                                                                                                                               
      g++ gcc openjdk-8-jdk \                                                                                                                                  
      zlib1g-dev libarchive-dev \                                                                                                                              
      ca-certificates-java && \                                                                                                                                
    apt-get clean                                                                                                                                              

RUN cd /opt && \                                                                                                                                               
    git clone https://github.com/google/bazel/ && \                                                                                                            
    cd bazel && \                                                                                                                                              
    git checkout 76023b9180d7a18defc526126a943fab684971dc && \                                                                                                 
    ./compile.sh && \                                                                                                                                          
    ln -s /opt/bazel/output/bazel /usr/bin/

ENTRYPOINT ["/usr/bin/bazel"]                                                                                                                                  
CMD []

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 16 (13 by maintainers)

Commits related to this issue

Most upvoted comments

Does adding a bazelrc file with “startup --batch” in it and then export BAZELRC=/path/to/bazelrc fix the issue?