Skip to content

Commit 5715bfc

Browse files
authored
Update README.rst
Tried adding some new documentation on extending the Docker image (this is pretty general documentation for adding packages in Docker images, but the note about the user is not immediately obvious) CC @JohnCremona
1 parent f623285 commit 5715bfc

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

README.rst

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,57 @@ It also targets a much broader community, with the potential to
7272
relieve the SageMath community from maintaining a custom solution.
7373
On the other hand it's still relatively recent and quickly evolving
7474
technology with less settled sustainability. Also the SageMath Cell
75-
has been optimized to be more reactive on startup and reduce
75+
has been optimized to be more reactive on startup and reduceapt
7676
resource consumption. Those optimizations have not yet been ported to
7777
Thebe+binder.
7878

7979
See also `thebe.rst <thebe.rst>`_ for additional reader-oriented notes.
8080

81+
Extending the sagemath Docker image
82+
-----------------------------------
83+
84+
The sample [`Dockerfile`](https://github.com/sagemath/sage-binder-env/blob/master/Dockerfile)
85+
in this repository is based on the official `sagemath/sagemath` Docker image. It includes
86+
Sage itself, and all the software packages typically included in a standard Sage installation,
87+
though not *everything* (in particular not optional Sage SPKGs, or other system software
88+
packages).
89+
90+
So in order to install additional Sage SPKGs it is possible to include a line like
91+
92+
RUN sage -i <spkg-name>
93+
94+
in the `Dockerfile`. Note, due to a current shortcoming in the official Docker image it is
95+
also necessary to install the `make` system package before running `sage -i`. See the
96+
next section.
97+
98+
Installing additional system packages
99+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
100+
101+
To add additional software packages a couple more steps are involved,
102+
albeit relatively simple. The thing to understand about the `sagemath/sagemath` image is
103+
that by default it puts you in a user called `sage`, so in order to install system packages
104+
it is necessary, when extending the image, to first switch back to the `root` user.
105+
Then, because the image is based on Ubuntu, the `apt-get` command can be used to install
106+
Ubuntu packages. The canonical way to do this in a `Dockerfile` involves updating the
107+
APT cache, installing the packages, and then cleaning up the APT cache again all within
108+
a single command (this is in order to keep cache files out of the image):
109+
110+
USER root
111+
RUN apt-get -qq update \
112+
&& apt-get -qq install -y --no-install-recommends <packages-to-install> \
113+
&& apt-get -qq clean
114+
USER sage
115+
116+
Finally, just make sure toward the end of the `Dockerfile` that you switch the image
117+
user back to `sage` (so that when users run the container they are not running it as
118+
`root`.
119+
120+
81121
Authors
82122
-------
83123

84124
Nicolas M. Thiéry
125+
E. Madison Bray
85126

86127
The demo notebooks for GAP, Singular, and Pari were written by the
87128
authors of the respective kernels. See the

0 commit comments

Comments
 (0)