From charlesreid1

(Created page with "Git checkout the docker repo for mongodb: https://charlesreid1.com:3000/docker/d-mongodb Make the container with the make command The container should run, and /opt/mongodb...")
 
No edit summary
Line 3: Line 3:
Make the container with the make command
Make the container with the make command


The container should run, and /opt/mongodb on the host machine will be mounted inside the Docker container, so that all database data will be persistent
If the container is already made, just run the run_container script:


To attach to the container, use docker exec:
<pre>
./run_container.sh
</pre>
 
This will run the docker run command.
 
The final docker run command in the repo's scripts looks like this:
 
<pre>
docker run \
    --name happy_mongo \
    -p <IP-ADDRESS-NUMBER-1>:27017:27017 \
    -p <IP-ADDRESS-NUMBER-2>:27017:27017 \
    -v /opt/mongodb:/data/db \
    -d \
    -ti jupitermongo
</pre>
 
This starts a container with the name happy_mongo (the --name flag)
 
The -p flags bind this docker instance to two ports: one on the host's IP address IP-ADDRESS-NUMBER-1, the other on IP-ADDRESS-NUMBER-2.
 
The -v flag tells mongodb to mount the host's /opt/mongodb directory as the local data directory, to persist changes to the database.
 
The -d flag tells docker to run this in the background.
 
The -ti flag specifies which container to run (see build script).
 
To attach to the container once it is already running, use docker exec:


<pre>
<pre>

Revision as of 08:40, 31 January 2018

Git checkout the docker repo for mongodb: https://charlesreid1.com:3000/docker/d-mongodb

Make the container with the make command

If the container is already made, just run the run_container script:

./run_container.sh

This will run the docker run command.

The final docker run command in the repo's scripts looks like this:

docker run \
    --name happy_mongo \
    -p <IP-ADDRESS-NUMBER-1>:27017:27017 \
    -p <IP-ADDRESS-NUMBER-2>:27017:27017 \
    -v /opt/mongodb:/data/db \
    -d \
    -ti jupitermongo

This starts a container with the name happy_mongo (the --name flag)

The -p flags bind this docker instance to two ports: one on the host's IP address IP-ADDRESS-NUMBER-1, the other on IP-ADDRESS-NUMBER-2.

The -v flag tells mongodb to mount the host's /opt/mongodb directory as the local data directory, to persist changes to the database.

The -d flag tells docker to run this in the background.

The -ti flag specifies which container to run (see build script).

To attach to the container once it is already running, use docker exec:

docker exec -ti happy_mongo /bin/bash

This will give you a shell inside the MongoDB docker machine. From there, you can debug problems in the container, update the database, run admin commands, etc.