comparison Sphinx/source/users/docker.rst @ 673:767c2550fa00

environment variable in docker compose
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 06 May 2021 12:37:40 +0200
parents b3e75cef601d
children 17c1ff4e6ae4
comparison
equal deleted inserted replaced
672:8bda16db46cf 673:767c2550fa00
145 <https://docs.docker.com/compose/compose-file/#secrets>`__ (note that 145 <https://docs.docker.com/compose/compose-file/#secrets>`__ (note that
146 the related option ``configs`` could in theory be better, 146 the related option ``configs`` could in theory be better,
147 unfortunately it is only available to `Docker Swarm 147 unfortunately it is only available to `Docker Swarm
148 <https://github.com/docker/compose/issues/5110>`__). 148 <https://github.com/docker/compose/issues/5110>`__).
149 149
150 .. highlight:: yml 150 .. highlight:: yaml
151 151
152 First create the ``docker-compose.yml`` file as follows (this one uses 152 First create the ``docker-compose.yml`` file as follows (this one uses
153 the `YAML file format <https://en.wikipedia.org/wiki/YAML>`__):: 153 the `YAML file format <https://en.wikipedia.org/wiki/YAML>`__)::
154 154
155 version: '3.1' # Secrets are only available since this version of Docker Compose 155 version: '3.1' # Secrets are only available since this version of Docker Compose
159 command: /run/secrets/ # Path to the configuration files (stored as secrets) 159 command: /run/secrets/ # Path to the configuration files (stored as secrets)
160 ports: 160 ports:
161 - 4242:4242 161 - 4242:4242
162 - 8042:8042 162 - 8042:8042
163 secrets: 163 secrets:
164 - orthanc.json 164 - orthanc.json
165 environment:
166 - ORTHANC_NAME=HelloWorld
165 secrets: 167 secrets:
166 orthanc.json: 168 orthanc.json:
167 file: orthanc.json 169 file: orthanc.json
168 170
169 .. highlight:: json 171 .. highlight:: json
170 172
171 Then, place the configuration file ``orthanc.json`` next to the 173 Then, place the configuration file ``orthanc.json`` next to the
172 ``docker-compose.yml`` file. Here is a minimalist ``orthanc.json``:: 174 ``docker-compose.yml`` file. Here is a minimalist ``orthanc.json``::
173 175
174 { 176 {
175 "Name" : "Orthanc in Docker", 177 "Name" : "${ORTHANC_NAME} in Docker Compose",
176 "RemoteAccessAllowed" : true 178 "RemoteAccessAllowed" : true
177 } 179 }
178 180
179 .. highlight:: bash 181 .. highlight:: bash
180 182
182 configuration options for Orthanc and all its plugins. The container 184 configuration options for Orthanc and all its plugins. The container
183 can then be started as follows:: 185 can then be started as follows::
184 186
185 $ docker-compose up 187 $ docker-compose up
186 188
187 189 Note how the `environment variable
190 <https://docs.docker.com/compose/environment-variables/>`__
191 ``ORTHANC_NAME`` has been used in order to easily adapt the
192 configuration of Orthanc. This results from the fact that Orthanc
193 injects :ref:`environment variables <orthanc-environment-variables>`
194 once reading the content of its configuration files (since Orthanc
195 1.5.0).
196
197
188 Making the Orthanc database persistent 198 Making the Orthanc database persistent
189 -------------------------------------- 199 --------------------------------------
190 200
191 The filesystem of Docker containers is volatile (its content is 201 The filesystem of Docker containers is volatile (its content is
192 deleted once the container stops). You can make the Orthanc database 202 deleted once the container stops). You can make the Orthanc database
259 269
260 $ docker inspect --format '{{ .NetworkSettings.IPAddress }}' some-postgres 270 $ docker inspect --format '{{ .NetworkSettings.IPAddress }}' some-postgres
261 $ docker inspect --format '{{ .NetworkSettings.Ports }}' some-postgres 271 $ docker inspect --format '{{ .NetworkSettings.Ports }}' some-postgres
262 $ docker run --rm --entrypoint=cat jodogne/orthanc-plugins /etc/orthanc/orthanc.json > /tmp/orthanc.json 272 $ docker run --rm --entrypoint=cat jodogne/orthanc-plugins /etc/orthanc/orthanc.json > /tmp/orthanc.json
263 273
264 .. highlight:: json 274 .. highlight:: text
265 275
266 Add the following section to ``/tmp/orthanc.json`` (adapting the 276 Add the following section to ``/tmp/orthanc.json`` (adapting the
267 values Host and Port to what docker inspect said above):: 277 values Host and Port to what docker inspect said above)::
268 278
269 "PostgreSQL" : { 279 "PostgreSQL" : {