Make sure examples work, lots of wordsmithing and reorganizing for clarity.
[arvados.git] / doc / user / topics / arv-docker.html.textile.liquid
1 ---
2 layout: default
3 navsection: userguide
4 title: "Working with Docker images"
5 ...
6 {% comment %}
7 Copyright (C) The Arvados Authors. All rights reserved.
8
9 SPDX-License-Identifier: CC-BY-SA-3.0
10 {% endcomment %}
11
12 This page describes how to set up the runtime environment (e.g., the programs, libraries, and other dependencies needed to run a job) that a workflow step will be run in using "Docker.":https://www.docker.com/  Docker is a tool for building and running containers that isolate applications from other applications running on the same node.  For detailed information about Docker, see the "Docker User Guide.":https://docs.docker.com/userguide/
13
14 This page describes:
15
16 # "Create a custom image using a Dockerfile":#create
17 # "Uploading an image to Arvados":#upload
18 # "Sources of pre-built bioinformatics Docker images":#sources
19
20 {% include 'tutorial_expectations_workstation' %}
21
22 You also need ensure that "Docker is installed,":https://docs.docker.com/installation/ the Docker daemon is running, and you have permission to access Docker.  You can test this by running @docker version@.  If you receive a permission denied error, your user account may need to be added to the @docker@ group.  If you have root access, you can add yourself to the @docker@ group using @$ sudo addgroup $USER docker@ then log out and log back in again; otherwise consult your local sysadmin.
23
24 h2(#create). Create a custom image using a Dockerfile
25
26 This example shows how to create a Docker image and add the R package.
27
28 First, create new directory called @docker-example@, in that directory create a file called @Dockerfile@.
29
30 <notextile>
31 <pre><code>$ <span class="userinput">mkdir docker-example-r-base</span>
32 $ <span class="userinput">cd docker-example-r-base</span>
33 </code></pre>
34 </notextile>
35
36 <notextile>
37 <pre><code>FROM ubuntu:bionic
38 RUN apt-get update && apt-get -yq --no-install-recommends install r-base-core
39 </code></pre>
40 </notextile>
41
42 The "RUN" command is executed inside the container and can be any shell command line.  You are not limited to installing Debian packages.  You may compile programs or libraries from source and install them, edit systemwide configuration files, use other package managers such as @pip@ or @gem@, and perform any other customization necessary to run your program.
43
44 You can also visit the "Docker tutorial":https://docs.docker.com/get-started/part2/ for more information and examples.
45
46 You should add your Dockerfiles to the same source control repository as the Workflows that use them.
47
48 h3. Create a new image
49
50 We're now ready to create a new Docker image.  Use @docker build@ to create a new image from the Dockerfile.
51
52 <notextile>
53 <pre><code>docker-example-r-base$ <span class="userinput">docker build -t docker-example-r-base .</span>
54 </code></pre>
55 </notextile>
56
57 h3. Verify image
58
59 Now we can verify that "R" is installed:
60
61 <notextile>
62 <pre><code>$ <span class="userinput">docker run -ti docker-example-r-base</span>
63 root@57ec8f8b2663:/# R
64
65 R version 3.4.4 (2018-03-15) -- "Someone to Lean On"
66 Copyright (C) 2018 The R Foundation for Statistical Computing
67 Platform: x86_64-pc-linux-gnu (64-bit)
68 </code></pre>
69 </notextile>
70
71 h2(#upload). Upload your image
72
73 Finally, we are ready to upload the new Docker image to Arvados.  Use @arv-keepdocker@ with the image repository name to upload the image.  Without arguments, @arv-keepdocker@ will print out the list of Docker images in Arvados that are available to you.
74
75 <notextile>
76 <pre><code>$ <span class="userinput">arv-keepdocker docker-example-r-base</span>
77 2020-06-29 13:48:19 arvados.arv_put[769] INFO: Creating new cache file at /home/peter/.cache/arvados/arv-put/39ddb51ebf6c5fcb3d713b5969466967
78 206M / 206M 100.0% 2020-06-29 13:48:21 arvados.arv_put[769] INFO:
79
80 2020-06-29 13:48:21 arvados.arv_put[769] INFO: Collection saved as 'Docker image docker-example-r-base:latest sha256:edd10'
81 x20vs-4zz18-0tayximqcyb6uf8
82
83 $ <span class="userinput">arv-keepdocker images</span>
84 REPOSITORY                      TAG         IMAGE ID      COLLECTION                     CREATED
85 docker-example-r-base           latest      sha256:edd10  x20vs-4zz18-0tayximqcyb6uf8    Mon Jun 29 17:46:16 2020
86 </code></pre>
87 </notextile>
88
89 You are now able to specify the runtime environment for your program using @DockerRequirement@ in your workflow:
90
91 <pre>
92 hints:
93   DockerRequirement:
94     dockerPull: docker-example-r-base
95 </pre>
96
97 h3. Uploading Docker images to a shared project
98
99 Docker images are subject to normal Arvados permissions.  If wish to share your Docker image with others you should use @arv-keepdocker@ with the @--project-uuid@ option to add the image to a shared project and ensure that metadata is set correctly.
100
101 <notextile>
102 <pre><code>$ <span class="userinput">arv-keepdocker docker-example-r-base --project-uuid zzzzz-j7d0g-xxxxxxxxxxxxxxx</span>
103 </code></pre>
104 </notextile>
105
106 h2(#sources). Sources of pre-built images
107
108 In addition to creating your own contianers, there are a number of resources where you can find bioinformatics tools already wrapped in container images:
109
110 "BioContainers":https://biocontainers.pro/
111
112 "Dockstore":https://dockstore.org/
113
114 "Docker Hub":https://hub.docker.com/