@@ -158,3 +158,88 @@ Open a shell session to a running container in your database resource
158158 > 120
159159
160160.. seealso:: :manual:`Operating System Configuration </administration/production-checklist-operations/#linux>` in the MongoDB Manual.
161+
162+ Build Custom Images with Dockerfile Templates
163+ ---------------------------------------------
164+
165+ You can modify MongoDB Dockerfile templates to create custom
166+ |k8s-op-short| images that suit your use case. To build a
167+ custom image, you need:
168+
169+ - Your custom Dockerfile, modified from a MongoDB template.
170+
171+ - The MongoDB-provided context image for your template.
172+
173+ MongoDB Dockerfile Templates
174+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
175+
176+ The Dockerfiles used to build container images are publicly
177+ available from the
178+ `MongoDB Enterprise Kubernetes GitHub repository <https://github.com/mongodb/mongodb-enterprise-kubernetes/tree/master/dockerfiles>`__.
179+
180+ The Dockerfile directory is organized by resource name, version and
181+ distribution:
182+
183+ .. code-block:: sh
184+ :copyable: false
185+
186+ ├── <resource name>
187+ │ └── <image version>
188+ │ └── <base distribution>
189+ │ └── Dockerfile template
190+
191+ Copy the template you want to use to your own Dockerfile and modify as
192+ desired.
193+
194+ Context Images
195+ ~~~~~~~~~~~~~~
196+
197+ To build an image from any MongoDB Dockerfile template, you must supply
198+ its context image.
199+
200+ Each Dockerfile template has one associated context image, retrievable
201+ from the same `Quay.io <https://quay.io/>`__ registry as the original
202+ images. Context image are always tagged in the format
203+ ``quay.io/mongodb/<resource-name>:<image-version>-context``.
204+
205+ To supply a context image to ``docker build``, include the
206+ ``--build-arg`` option with the ``imagebase`` variable set to a
207+ Quay.io tag, where ``<resource-name>`` and ``<image-version>`` match
208+ your Dockerfile template.
209+
210+ .. example::
211+ If you want to build the ``mongodb-enterprise-database`` version
212+ 2.0.0 image for any distribution, include:
213+
214+ .. code-block:: sh
215+ :copyable: false
216+
217+ --build-arg imagebase=quay.io/mongodb/mongodb-enterprise-database:2.0.0-context
218+
219+ ``docker build`` Example
220+ ~~~~~~~~~~~~~~~~~~~~~~~~
221+
222+ The Ubuntu distribution for ``mongodb-enterprise-operator`` version
223+ 1.9.1 is based on ``ubuntu:1604`` by default. In this example, that
224+ base Dockerfile template is modified to use ``ubuntu:1804`` and
225+ saved as ``myDockerfile``.
226+
227+ The following command builds the custom image and gives it the tag
228+ ``1.9.1-ubuntu-1804``:
229+
230+ .. code-block:: sh
231+ :copyable: false
232+
233+ cat myDockerfile | docker build --build-arg imagebase=quay.io/mongodb/mongodb-enterprise-operator:1.9.1-context \
234+ --tag mongodb-enterprise-operator:1.9.1-ubuntu-1804 -
235+
236+ .. note::
237+
238+ Include a hyphen (``-``) at the end of ``docker build`` to read
239+ the output of ``cat myDockerfile`` instead of providing a
240+ local directory as build context.
241+
242+ .. seealso::
243+
244+ To learn more about ``docker build``, see the
245+ `Docker documentation <https://docs.docker.com/engine/reference/commandline/build/>`__.
0 commit comments