Skip to content

Commit d1822ff

Browse files
authored
Merge pull request #231 from consideRatio/pr/update-custom-dockerfile-docs
2 parents b686a46 + 0340f04 commit d1822ff

File tree

1 file changed

+45
-12
lines changed

1 file changed

+45
-12
lines changed

doc/tutorials/dockerfile.md

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,8 @@ If you want to use a pre-existing Docker image, you may source it in your
4444
Dockerfile. For example, this code sources the Jupyter-Scipy notebook:
4545

4646
```Dockerfile
47-
4847
# Note that there must be a tag
4948
FROM jupyter/scipy-notebook:cf6258237ff9
50-
5149
```
5250

5351
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:
8684
So in your dockerfile, you should have a command such as:
8785

8886
```Dockerfile
89-
90-
RUN pip install --no-cache-dir notebook==5.*
91-
87+
RUN pip install --no-cache-dir notebook
9288
```
9389

9490
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:
10197
2. It must explicitly specify a tag in the image you source.
10298

10399
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
105101
naming conventions differ between images, so we recommend using
106102
the SHA tag of the image.
107103

108104
Here's an example of a Dockerfile `FROM` statement that would work.
109105

110-
```
106+
```Dockerfile
111107
FROM jupyter/scipy-notebook:cf6258237ff9
112108
```
113109

@@ -119,16 +115,17 @@ For a Dockerfile to work on Binder, it must meet the following requirements:
119115

120116
or
121117

122-
```
118+
```Dockerfile
123119
FROM jupyter/scipy-notebook:latest
124120
```
121+
125122
3. It must set up a user whose uid is {}`1000`.
126123
It is bad practice to run processes in containers as root, and on binder
127124
we do not allow root container processes. If you are using an ubuntu or
128125
debian based container image, you can create a user easily with the following
129126
directives somewhere in your Dockerfile:
130127

131-
```
128+
```Dockerfile
132129
ARG NB_USER=jovyan
133130
ARG NB_UID=1000
134131
ENV USER ${NB_USER}
@@ -144,14 +141,15 @@ For a Dockerfile to work on Binder, it must meet the following requirements:
144141
This is the user that will be running the jupyter notebook process
145142
when your repo is launched with binder. So any files you would like to
146143
be writeable by the launched binder notebook should be owned by this user.
144+
147145
4. It must copy its contents to the `$HOME` directory and change permissions.
148146

149147
To make sure that your repository contents are available to users,
150148
you must copy all contents to `$HOME` and then make this folder
151149
owned by the user you created in step 3. If you used the snippet provided
152150
in step 3, you can accomplish this copying with the following snippet:
153151

154-
```
152+
```Dockerfile
155153
# Make sure the contents of our repo are in ${HOME}
156154
COPY . ${HOME}
157155
USER root
@@ -162,11 +160,12 @@ For a Dockerfile to work on Binder, it must meet the following requirements:
162160
This chown is required because Docker will be default
163161
set the owner to `root`, which would prevent users from editing files. Note that the repository
164162
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
166164
repository will be used even after changes to the repository.
165+
167166
5. It must accept command arguments. The Dockerfile will effectively be launched as:
168167

169-
```
168+
```shell
170169
docker run <image> jupyter notebook <arguments from the mybinder launcher>
171170
```
172171

@@ -179,6 +178,40 @@ For a Dockerfile to work on Binder, it must meet the following requirements:
179178

180179
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.
181180

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+
182215
## Ensuring reproducibility with Dockerfiles
183216

184217
Ensuring that your Binder environment is reproducible requires extra

0 commit comments

Comments
 (0)