You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/tutorials/dockerfile.md
+45-12Lines changed: 45 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,10 +44,8 @@ If you want to use a pre-existing Docker image, you may source it in your
44
44
Dockerfile. For example, this code sources the Jupyter-Scipy notebook:
45
45
46
46
```Dockerfile
47
-
48
47
# Note that there must be a tag
49
48
FROM jupyter/scipy-notebook:cf6258237ff9
50
-
51
49
```
52
50
53
51
See [Preparing your Dockerfile](preparing your dockerfile) for instructions on how to
@@ -86,9 +84,7 @@ For a Dockerfile to work on Binder, it must meet the following requirements:
86
84
So in your dockerfile, you should have a command such as:
87
85
88
86
```Dockerfile
89
-
90
-
RUN pip install --no-cache-dir notebook==5.*
91
-
87
+
RUN pip install --no-cache-dir notebook
92
88
```
93
89
94
90
If you would like to use the repository with an authenticated Binder you
@@ -101,13 +97,13 @@ For a Dockerfile to work on Binder, it must meet the following requirements:
101
97
2. It must explicitly specify a tag in the image you source.
102
98
103
99
When sourcing a pre-existing Docker image with `FROM`,
104
-
**a tag is required**. The tag *cannot* be `latest`. Note that tag
100
+
**a tag is required**. The tag *cannot* be `latest`. Note that tag
105
101
naming conventions differ between images, so we recommend using
106
102
the SHA tag of the image.
107
103
108
104
Here's an example of a Dockerfile `FROM` statement that would work.
109
105
110
-
```
106
+
```Dockerfile
111
107
FROM jupyter/scipy-notebook:cf6258237ff9
112
108
```
113
109
@@ -119,16 +115,17 @@ For a Dockerfile to work on Binder, it must meet the following requirements:
119
115
120
116
or
121
117
122
-
```
118
+
```Dockerfile
123
119
FROM jupyter/scipy-notebook:latest
124
120
```
121
+
125
122
3. It must set up a user whose uid is {}`1000`.
126
123
It is bad practice to run processes in containers as root, and on binder
127
124
we do not allow root container processes. If you are using an ubuntu or
128
125
debian based container image, you can create a user easily with the following
129
126
directives somewhere in your Dockerfile:
130
127
131
-
```
128
+
```Dockerfile
132
129
ARG NB_USER=jovyan
133
130
ARG NB_UID=1000
134
131
ENV USER ${NB_USER}
@@ -144,14 +141,15 @@ For a Dockerfile to work on Binder, it must meet the following requirements:
144
141
This is the user that will be running the jupyter notebook process
145
142
when your repo is launched with binder. So any files you would like to
146
143
be writeable by the launched binder notebook should be owned by this user.
144
+
147
145
4. It must copy its contents to the `$HOME` directory and change permissions.
148
146
149
147
To make sure that your repository contents are available to users,
150
148
you must copy all contents to `$HOME` and then make this folder
151
149
owned by the user you created in step 3. If you used the snippet provided
152
150
in step 3, you can accomplish this copying with the following snippet:
153
151
154
-
```
152
+
```Dockerfile
155
153
# Make sure the contents of our repo are in ${HOME}
156
154
COPY . ${HOME}
157
155
USER root
@@ -162,11 +160,12 @@ For a Dockerfile to work on Binder, it must meet the following requirements:
162
160
This chown is required because Docker will be default
163
161
set the owner to `root`, which would prevent users from editing files. Note that the repository
164
162
should in general be clone with `COPY`; although `RUN git clone ...` is a valid command for the
165
-
`Dockerfile`, it does not invalidate the build cache of mybinder. Thus, if available, the the cached
163
+
`Dockerfile`, it does not invalidate the build cache of mybinder. Thus, if available, the the cached
166
164
repository will be used even after changes to the repository.
165
+
167
166
5. It must accept command arguments. The Dockerfile will effectively be launched as:
168
167
169
-
```
168
+
```shell
170
169
docker run <image> jupyter notebook <arguments from the mybinder launcher>
171
170
```
172
171
@@ -179,6 +178,40 @@ For a Dockerfile to work on Binder, it must meet the following requirements:
179
178
180
179
For more information, and a shell wrapper example, please see the [Dockerfile best practices: ENTRYPOINT](<https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#entrypoint>) documentation.
181
180
181
+
You can build and test your image locally like this.
182
+
183
+
1. Try building your image.
184
+
185
+
```shell
186
+
docker build -t my-image .
187
+
```
188
+
189
+
2. Try starting a container from the image.
190
+
191
+
```shell
192
+
docker run -it --rm -p 8888:8888 my-image jupyter-notebook --ip=0.0.0.0 --port=8888
193
+
```
194
+
195
+
3. Inspect the container from terminal.
196
+
197
+
Verify your user has an id of `1000` and ownership of files in the home folder.
198
+
199
+
```shell
200
+
docker run -it --rm my-image bash
201
+
```
202
+
203
+
```shell
204
+
# what username do i have?
205
+
whoami
206
+
# what user id do i have?
207
+
id -u
208
+
# what is the current working directory?
209
+
pwd
210
+
# who is the owner of the files in the users home directory?
211
+
ls -alh ~
212
+
```
213
+
214
+
182
215
## Ensuring reproducibility with Dockerfiles
183
216
184
217
Ensuring that your Binder environment is reproducible requires extra
0 commit comments