Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker RUN used in Cloud documentation. #173

Closed
jackwootton opened this issue Sep 26, 2017 · 4 comments
Closed

Docker RUN used in Cloud documentation. #173

jackwootton opened this issue Sep 26, 2017 · 4 comments
Labels

Comments

@jackwootton
Copy link

jackwootton commented Sep 26, 2017

Google's documentation for Building a Docker Image makes use of RUN:

FROM gcr.io/google_appengine/python

RUN apt-get update && \
    apt-get install -y python2.7 python-pip && \
    apt-get clean && \
    rm /var/lib/apt/lists/*_*

ADD . /app
WORKDIR /app

RUN pip install -r requirements.txt
ENTRYPOINT ["gunicorn", "-b", ":8080", "main:app"]

Sample Dockerfile at python-docs-samples/endpoints/getting-started/Dockerfile.custom.

I've read through Supporting RUN instructions? - but it remains unclear to me how this works with pip install.

@jackwootton jackwootton changed the title Docker RUN Docker RUN used in Cloud documentation. Sep 26, 2017
@mattmoor
Copy link
Contributor

(to rehash that thread a little bit)
The way Bazel builds Docker images is fundamentally different from the way just about everyone else builds Docker images. In particular, we don't support RUN because of two main reasons:

  1. Virtually everything folks do in RUN isn't reproducible.
  2. The way the Docker daemon evaluates RUN is never reproducible.

This can be a bit of a pill for folks used to Dockerfile's convenience, but if you can manage to live within these constraints you get a ton of nice properties that are virtually impossible with traditional methods. These properties (and constraints) are largely projections of Bazel's principles.


Your real question seems to be: How do I make my Bazel application consume PIP dependencies?

That is a great question, and a useful feature independent of its use in Docker images! I recently put together bazelbuild/rules_python to solve this looooooong-standing Bazel issue (in part because it was such a common ask from rules_docker users).

I think you'd be interested in seeing this example. It combines bazelbuild/rules_python to import PIP dependencies into Bazel, and then assembles a Python image using py_image from this repository.

The reason the sample isn't merged is because of this issue, which has a pretty straightforward workaround.

@fikriauliya
Copy link

@mattmoor I have seen your example, please correct me if my understanding is incorrect:

  • You run pip install in the host environment (in WORKSPACE)
  • The generated files are included into docker image via deps param
  • This way, we don't need RUN instruction as in Dockerfile

I have similar cases to run npm install and bundle install. Those are currently run in my Dockerfile. Learning from your approach, can I simple run npm install and bundle install in the host (in WORKSPACE) and copy the downloaded dependencies (packages folder in the case of npm install) to Docker via deps?

@mattmoor
Copy link
Contributor

rules_nodejs has an npm_install that works similarly to pip_install. I'm not familiar with bundle install?

@fikriauliya
Copy link

fikriauliya commented Feb 15, 2018

bundle install is to install Ruby dependency. Since it's not yet supported, I am thinking to create myself.
Any article/sample code to the recommended way to install external dependencies not managed by Bazel (e.g. pip, npm)? Or are my points above sufficiently correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants