Seeking guidance on building Docker images with Bazel (multi-host-platform)

44 views
Skip to first unread message

Itamar Ostricher

unread,
Apr 4, 2018, 7:49:16 AM4/4/18
to bazel-discuss
Hi all,

Bazel newbie here, seeking guidance around (supposedly?) basic usage.
Feel free to point me at existing relevant docs, that I failed locating on my own...

What I'm trying to achieve:
1. Build a couple of Docker images.
2. Be able to run the build on Linux & OS X hosts (bonus points for Windows host too), with Linux Docker images as the target.
3. The build should run in a sandbox that doesn't assume anything about the host environment (e.g. require just Bazel and maybe Docker on the host, not clang etc.). I am under the impression that this is inherent to Bazel, though after playing with it a little I'm not sure.

My existing code, along with working Dockerfiles, can be found here: https://github.com/itamaro/hello-docker

Specifically, this is one of the Dockerfiles for a simple C++ echo server.
As you can see, this Dockerfile runs a build (using clang) in a build-container, in which I install the build toolchain and dependencies (e.g. clang & boost-dev), followed by an app-container in which I install only the runtime dependencies (e.g. no clang and only runtime boost) and copy the compiled binary from the build-container.
My goal is to figure out how to end up with the same final artifact (a relatively slim Docker image with minimal runtime dependencies) using Bazel, and be able to build the same artifact from Linux as well as OS X.

Similar story for the Python echo server and Go echo server.

I managed to find Bazel rules_docker and rules_boost, but I'm not quite sure how to proceed.

Any guidance would be much appreciated!
Itamar.

ittai zeidman

unread,
Apr 6, 2018, 1:05:53 AM4/6/18
to bazel-discuss
Hi Itamar,
I’m really not a docker expert but as far as I understand the current (somewhat) stable support for creating docker images doesn’t support dockerfiles since inherently they can allow non reproducible changes (run apt-get).
The support I’m familiar with is $lang_container where you build a python_binary (for example) and then have a python_container that depends on it and essentially creates a docker container which packages the python deployable with its dependencies in the container and runs it when the container is run.
Others here might have more/better information to give
Reply all
Reply to author
Forward
0 new messages