-
Notifications
You must be signed in to change notification settings - Fork 18.7k
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
Add a docker image for caffe development. #3518
Conversation
Thanks for the pointers, I will have a look at the best practices and adjust the docker file accordingly. The code to change the user started as a more general script, and I can try to simplify it to be better suited to the task of building caffe. In terms of usefulness, I use the image locally and thought I would submit it as a pull request so that it is part of caffe as it was also mentioned in #2313 (comment). If it is not found to be useful, we can close the pull request without merging, and I will move the utilities to its own repository. |
I just think there is a lot of code to set the user, it might scare Docker beginners. But don't get me wrong, I think this PR is very useful, the Caffe users list is full of topics where people are struggling to compile Caffe on their machine. You don't need to convince me of the benefits offered by Docker, but I'm not a maintainer of Caffe.
|
This is excellent. This will allow a reliable way to guide students through tutorials, as well as let programmers cleanly keep up to date with caffe releases as well as keep their scripts running on previous versions if breaking changes occur. Hopefully there will be a repository on dockerhub of images of past versions (from here on out). I hope the dockerfile can get some attention and get "generalized" or whatever it needs to be a standard way of using caffe. |
Given that there seems to be demand, what needs to be changed/added so that this is as useful as possible? Some thoughts:
Something that would be nice to have would be that the docker images be tagged using the Caffe version. What is the status of #3311? |
I think those are good ideas, I would keep things simple as a start, it will be easier for the project maintainers to review, especially if they don't have any prior experience with Docker. |
6b63146
to
6546ca7
Compare
I have made some changes to the Dockerfiles. There are now two (CPU and GPU) Dockerfiles which provide runtime containers. These can be used as replacements for the caffe executable? I have also simplified the script for running the development container somewhat. I would appreciate input wrt finishing this pull request off? Does BVLC have a Docker Hub orgainisation, for example, so that we can set up triggered builds there? Are there any comments related to where the Dockerfiles are specified, and whether other flavors (e.g. OpenBLAS, CUDA 7.0, non-CUDNN) should be made available? |
I think this is a good start, I don't think other flavors are required right now. The benefit of Docker is to bundle all the dependencies, so for instance cuDNN is already included in the image. It will be transparent for users. I would use the cmake build system actually instead of having to copy |
Ok. I will switch the docker files to Any comments on the location of the docker files? Or are |
Regarding the location: ask the maintainers, they are all labeled to this PR so they will probably answer when they have the time :) |
6a3ba7e
to
a890083
Compare
@elezar Are you done working on this PR? If you're done let me know so I can review it again. @shelhamer: you tagged this PR, is Docker going to be on your roadmap in the future? |
From my side, the Docker images are done. If someone could check out the PR |
Please squash all your patches into one for easier review (see |
462d18a
to
3141521
Compare
@flx42 I have squashed the changes, and tried to make the docker files more in keeping with the steps given on the installation website. I have also removed the additions (such as jupyter ports) which are not core to the requirements of the images. I have added Dockerfile generation options to the makefile (although they are themselves checked in) so that these are generated automatically from templates. This ensures that they are uniform, and adds some options in terms of extending these for future versions. |
wget | ||
|
||
# Install the python requirements. | ||
RUN wget https://raw.githubusercontent.com/BVLC/caffe/master/python/requirements.txt -O /tmp/requirements.txt && \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've never used docker so I'm definitely not an expert, but is it necessary to wget requirements.txt like this rather than getting it from the (presumably already downloaded) local copy of caffe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I mentioned in response to one of @flx42 's comments, the development
image is intended to be used to build caffe from source locally (with
folders mounted as volumes. See start_caffe_docker.sh
for example). This
means that the caffe source (and thus requirements.txt) is not available to
the image at build time. You will note that the runtime Dockerfiles (and
their corresponding templates) do use the locally available requirements
files.
Of course, if someone has a suggestion as to how this could be improved,
I'm all ears.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means that the caffe source (and thus requirements.txt) is not available to the image at build time.
Why not? The source is available locally because it was checked out (in order to get the Dockerfile
in the first place). Yes, you may need to run docker build
at a higher level (run it at the root level of the repo, and ignore some things in .dockerignore
to make it build faster), but everything is visible to the docker build script.
Why not just ADD
the single file to /tmp/
(ADD python/requirements.txt /tmp/
).
- If you use
ADD
and changerequirements.txt
, re-building the docker image will see the new version of the file, and use that. That will not happen withRUN
since the command does not change (and thus you will use a stale copy). - If you use
RUN
, the build will always use the remote master repository version (viawget
), leading to some unintuitive errors if one tries to editrequirements.txt
in a local copy and re-build the image.
462d18a
to
3141521
Compare
|
||
CMD bash | ||
# Clone Caffe repo and move into it | ||
RUN cd /opt && git clone https://github.com/BVLC/caffe.git && cd caffe && \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not instead require that you check out the repository, and then run docker build
inside it? The way you've written it, you can only create a runtime docker image for the remote master branch. What if I want to make a runtime image for my own build? People modify caffe and have local versions all the time.
A more flexible approach would be to use ADD
to add the local source files into /opt/
. You check out the code first, then run docker build -t <some-tag> docker/runtime/gpu/Dockerfile
.
@elezar How do you see these images as being used? I understand that you want to create a canonical version that uses the official master-branch code, but I don't the proposed code achieves that. The way it is written, the I agree that for development you want to mount in the source code, and that is indeed helpful. But for everything else that gets copied into the image itself, I think Alternatively, if you really want to use |
Thank you for joining the debate, @seanbell! Disclaimer: if you don't know, I'm a maintainer of https://github.com/NVIDIA/nvidia-docker Let's merge the answers into the main thread.
Not with his approach, he wants users to compile Caffe after shelling inside the container.
I think this use case is more suited to the "devel" image. The runtime image is precisely for people that don't want to do that. They want to start using Caffe, or they are already advanced users but they don't have custom layers. People do use deb packages sometimes, right? :) An advantage of this self-contained approach is that you don't need to clone the code, you can build a Dockerfile from GitHub directly:
I like the convenience of avoiding to copy the whole repo on my local file system. And the point of this runtime image is to rely on a pristine, well-tested version, you don't want to @seanbell, what you suggest sounds fine for the Retrospectively, I think it might be better to start simple by only including the runtime images in this PR. This would be sufficient for caffe newcomers during hands-on tutorials. |
Thanks for the comments @seanbell, and also the nice summary of the use cases @flx42. I think you may be right in suggesting that this pull request only include the runtime images. This is the use case that probably caters most to the target audience. That is to say people who want to quickly try caffe, or for a sort of archiving for particular versions. I will remove the other files for the time being and add them as a separate pull request (I should still be able to address my own use-case with some shell scripts, although the images may be larger than needed). With regards to:
Yes, that is true. I do have the following to add: |
I was able to build the However, the LeNet docker example fails because nvidia-docker neither recognizes Here is an example call
that ran fine. |
@shelhamer Yeah that's a bug in |
Alright, well I'm happy to merge once the example works whether by long options in this PR or a fix to nvidia-docker. @elezar feel free to force push an amended commit. (If you do amend, consider formatting the commit message so it has a "title" line <80 chars and then further description after a newline as it formats better on the command line and on github, but no worries.) |
e3059ec
to
7d62930
Compare
These can be used as direct replacements for the Caffe executable.
7d62930
to
6cba462
Compare
I have switched to the |
[build] Add docker images for running caffe out-of-the-box (caffe:cpu, caffe:gpu)
Thanks for the Caffe containers @elezar ! Next we'll figure out how to include these on the docker hub. |
nvidia-docker requires long args with equal sign as of docker 1.10: see BVLC#3518 (comment)
Fix flags for nvidia-docker from #3518
Thank you for the additional fix @shelhamer, this bug is embarrassing for us, we will fix it quickly. |
Thanks @shelhamer. As for getting the images onto Docker Hub, I see two options. Either one sets up an automated build on Docker Hub itself (I have already done this for https://hub.docker.com/r/elezar/caffe), or one builds the images as part of some CI/CD steps and pushes them. I think the latter is the route that NVIDIA follows for https://hub.docker.com/r/nvidia/. Maybe @flx42 could comment on this? I should add that for the automated builds on Docker Hub seem to be failing for the GPU images (with no log output). @flx42 do you have an idea what the reason for this may be? |
@elezar: we tried using the automated build on the DockerHub but we gave up on this idea because it was not suitable for our complex model with multiple images (see the discussion here). I don't know why it would fail on the Docker Hub, it used to work when I tested. |
nvidia-docker requires long args with equal sign as of docker 1.10: see BVLC#3518 (comment)
nvidia-docker requires long args with equal sign as of docker 1.10: see BVLC#3518 (comment)
nvidia-docker requires long args with equal sign as of docker 1.10: see BVLC#3518 (comment)
nvidia-docker requires long args with equal sign as of docker 1.10: see BVLC#3518 (comment)
nvidia-docker requires long args with equal sign as of docker 1.10: see BVLC#3518 (comment)
[build] Add docker images for running caffe out-of-the-box (caffe:cpu, caffe:gpu)
Fix flags for nvidia-docker from BVLC#3518
nvidia-docker requires long args with equal sign as of docker 1.10: see BVLC#3518 (comment)
nvidia-docker requires long args with equal sign as of docker 1.10: see BVLC#3518 (comment)
nvidia-docker requires long args with equal sign as of docker 1.10: see BVLC#3518 (comment)
nvidia-docker requires long args with equal sign as of docker 1.10: see BVLC#3518 (comment)
nvidia-docker requires long args with equal sign as of docker 1.10: see BVLC#3518 (comment)
nvidia-docker requires long args with equal sign as of docker 1.10: see BVLC#3518 (comment)
nvidia-docker requires long args with equal sign as of docker 1.10: see BVLC/caffe#3518 (comment)
The idea is to add docker files for Caffe. Both for development purposes (my original motivation) and for providing pre-built Caffe images. The following steps can be considered: