Skip to content

Commit 2e7d8c5

Browse files
committed
(DOCSP-37794): Backport DOCSP-37438 to v1.14. (#303)
* (DOCSP-37438): Added details about persisting data. * (DOCSP_37438): Incorporated Max's feedback. * (DOCSP-37438): Incorporated Sarah's feedback. * (DOCSP-37438): Incorporated final comments.
1 parent 5946068 commit 2e7d8c5

File tree

1 file changed

+143
-0
lines changed

1 file changed

+143
-0
lines changed

source/atlas-cli-deploy-docker.txt

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ deployment with `Docker Compose <https://docs.docker.com/compose/>`__.
100100
.. procedure::
101101
:style: normal
102102

103+
.. step:: Install and start Docker.
104+
105+
To learn more, see the `Docker documentation <https://docs.docker.com/desktop/install/mac-install/>`__.
106+
103107
.. step:: Install Docker Compose.
104108

105109
**Example:**
@@ -108,6 +112,9 @@ deployment with `Docker Compose <https://docs.docker.com/compose/>`__.
108112

109113
brew install docker-compose
110114

115+
To learn more, see the `Docker Compose install documentation
116+
<https://docs.docker.com/compose/install/>`__.
117+
111118
.. step:: Create a ``docker-compose.yaml`` file.
112119

113120
Create the ``docker-compose.yaml`` file in the same directory
@@ -163,6 +170,142 @@ deployment with `Docker Compose <https://docs.docker.com/compose/>`__.
163170

164171
mongosh mongodb://root:root@localhost:27778/?directConnection=true
165172

173+
Persist Data Across Runs with Docker Compose
174+
--------------------------------------------
175+
176+
You can persist data across multiple runs with `Docker Compose
177+
<https://docs.docker.com/compose/>`__. Persisting data helps to ensure
178+
that data isn't lost between runs. Data remains available across runs
179+
of Docker Compose.
180+
181+
.. procedure::
182+
:style: normal
183+
184+
.. step:: Install and start Docker.
185+
186+
To learn more, see the `Docker documentation <https://docs.docker.com/desktop/install/mac-install/>`__.
187+
188+
.. step:: Install Docker Compose.
189+
190+
**Example:**
191+
192+
.. code-block:: sh
193+
194+
brew install docker-compose
195+
196+
To learn more, see the `Docker Compose install documentation
197+
<https://docs.docker.com/compose/install/>`__.
198+
199+
.. step:: Create a script to start and stop your local deployment.
200+
201+
a. Create the following ``entrypoint.sh`` script file in the same
202+
directory that you run Docker Compose from:
203+
204+
.. code-block:: sh
205+
206+
#!/bin/bash
207+
stop_atlas() {
208+
echo "Stopping Atlas deployment..."
209+
atlas deployments stop
210+
}
211+
start_atlas() {
212+
echo "Starting Atlas deployment..."
213+
atlas deployments start
214+
}
215+
trap 'stop_atlas' SIGTERM SIGINT
216+
deployment_status=$(atlas deployments list | grep 'LOCAL')
217+
if [[ -z "$deployment_status" ]]; then
218+
echo "No local deployment found. Setting up..."
219+
atlas deployments setup dev --bindIpAll --username root --password $LOCALDEV_PASSWORD --type local --port 27017 --force
220+
else
221+
if [[ $deployment_status == *"STOPPED"* ]]; then
222+
start_atlas
223+
fi
224+
fi
225+
while true
226+
do
227+
tail -f /dev/null & wait ${!}
228+
done
229+
230+
#. Run the following command to make the script executable only
231+
by you:
232+
233+
.. code-block:: sh
234+
235+
chmod u+x entrypoint.sh
236+
237+
.. step:: Update your ``docker-compose.yaml`` file.
238+
239+
a. Update the ``docker-compose.yaml`` file to mount the necessary
240+
data directories as volumes.
241+
242+
**Example:**
243+
244+
.. code-block:: sh
245+
:linenos:
246+
247+
services:
248+
mongo:
249+
image: mongodb/atlas
250+
privileged: true
251+
volumes:
252+
- data-cni:/etc/cni
253+
- data-containers:/var/lib/containers
254+
- ./entrypoint.sh:/entrypoint.s
255+
ports:
256+
- 27017:27017
257+
environment:
258+
- LOCALDEV_PASSWORD={your-password}
259+
volumes:
260+
data-cni:
261+
data-containers:
262+
263+
#. Replace the ``{your-password}`` variable in the example with
264+
your password and save the file.
265+
266+
To learn more about the available options, see
267+
:ref:`atlas-deployments-setup`.
268+
269+
.. step:: Run Docker Compose.
270+
271+
The following command creates a local |service| deployment with
272+
|fts| capabilities enabled. It also returns a connection string.
273+
274+
**Example:**
275+
276+
.. code-block:: sh
277+
278+
docker-compose up
279+
280+
You can also run Docker Compose in `detached mode <https://docs.docker.com/reference/cli/docker/compose/up/#options>`__.
281+
282+
**Example:**
283+
284+
.. code-block:: sh
285+
286+
docker-compose up -d
287+
288+
.. step:: Connect to the local |service| deployment.
289+
290+
To connect to the local |service| deployment from the host (not
291+
container), copy and paste the following command, and replace
292+
the ``{connection_string}`` variable with your connection string.
293+
294+
.. note::
295+
296+
The following example uses {+mongosh+}, but you can use the
297+
connection method that you prefer.
298+
299+
.. code-block:: sh
300+
301+
mongosh {connection_string}
302+
303+
**Example:**
304+
305+
.. code-block:: sh
306+
307+
mongosh mongodb://root:{your-password}@localhost:27017/?directConnection=true
308+
166309
Supported Actions
167310
-----------------
168311

0 commit comments

Comments
 (0)