
{"id":7369,"date":"2020-03-04T13:34:20","date_gmt":"2020-03-04T13:34:20","guid":{"rendered":"https:\/\/rax-stg-wp-aws.com\/blogs\/deploy-mongodb-as-a-docker-container\/"},"modified":"2026-11-03T19:28:38","modified_gmt":"2026-11-03T19:28:38","slug":"deploy-mongodb-as-a-docker-container","status":"publish","type":"blogs","link":"https:\/\/www.rackspace.com\/en-gb\/blogs\/deploy-mongodb-as-a-docker-container\/","title":{"rendered":"Deploy MongoDB as a Docker container"},"content":{"rendered":"<p><strong>Introduction<\/strong><\/p>\n<p>One of the most accessible NoSQL databases, MongoDB\u00ae, has many available deployment options. In this post, I use Docker\u00ae to deploy MongoDB as a container and use the shell client to interact with that container.<\/p>\n<p>After you install Docker on your computer or server, perform the following steps<br \/>\nto deploy MongoDB as a Docker container:<\/p>\n<ol>\n<li>Download the latest or a specific MongoDB Docker image.<\/li>\n<li>Deploy an instance of MongoDB as a container.<\/li>\n<li>Interact with the MongoDB Docker container with basic shell operations.<\/li>\n<\/ol>\n<p><strong>Download the MongoDB Docker image<\/strong><\/p>\n<p>If you have Docker installed on your computer or server, you can get the MongoDB image from the Docker Hub container registry. Be sure to download the specific&nbsp;image version that you expect to use, such as mongo:4.0.4. You don&#8217;t have to specify the image version, but if you omit it, you get the most current version, which could result in an inconsistent experience because Mongo can update the&nbsp;latest version at any time.<\/p>\n<p>Executing the `<em>docker images<\/em>` command gives a list of images available on the server. In our case, it shows the MongoDB image with the tag 4.0.4 available for&nbsp;use.<\/p>\n<p>Use the following commands to download the MongoDB image and list your available images:<\/p>\n<p><em>&nbsp; &nbsp; # docker pull mongo:4.0.4<br \/>\n&nbsp; &nbsp; # docker images<\/em><\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26402-body-Picture1_20.png\" alt=\"mongodocker pic 1\" \/><\/p>\n<p><strong>Deploy an instance of MongoDB as a container&nbsp;<\/strong><\/p>\n<p>\nStart the container in detached, `<em>-d<\/em>`, mode. Because containers use ephemeralstorage, you should mount a volume, `<em>-v<\/em>`, to retain the data by providing the local path, <strong>\/data\/db<\/strong>. This path is the container&#8217;s internal directory. This action preserves the data on the host&#8217;s <strong>\/data\/db<\/strong>&nbsp;path even when you stop or&nbsp;remove the container. In the command, you provide a name, `&#8211;name`, for your&nbsp;container followed by the Docker image and a tag. In this case, I used&nbsp;<strong>mongo:4.0.4<\/strong>&nbsp;for the tag. The command returns a string with the&nbsp;container&#8217;s ID. The docker `<em>ps<\/em>` command shows a list of running containers.<\/p>\n<p><em>&nbsp; &nbsp; # docker run -d -v \/data\/db:\/data\/db &#8211;name mymongo mongo:4.0.4<br \/>\n&nbsp; &nbsp; # docker ps<\/em><\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26402-body-Picture2_19.png\" alt=\"mongodocker pic 2\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Interact with the MongoDB Docker container with the shell&nbsp;<\/strong><\/p>\n<p>To take advantage of a functional MongoDB deployment, you can interact with&nbsp;the database by using the shell client.&nbsp;Because you are running the container in detached mode, you should connect by&nbsp;using the interactive terminal. Use the following command to connect to your&nbsp;deployment, named <strong>mymongo<\/strong>, and start the bash shell:<\/p>\n<p><em># docker exec -it mymongo bash<\/em><br \/>\n&nbsp;<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26402-body-Picture3_14.png\" alt=\"mongodocker pic 3\" \/><\/p>\n<p>\nTo launch the MongoDB shell client, run the following command:<\/p>\n<p><em>&nbsp; &nbsp; # mongo&nbsp;<\/em><\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26402-body-Picture4_13.png\" alt=\"mongodocker pic 4\" \/><\/p>\n<p>From the MongoDB shell client, you can access all the functions outlined in the&nbsp;MongoDB documentation. For example, you can see what databases exist in your&nbsp;instance with the following command:&nbsp;<\/p>\n<p>&nbsp;<em>&gt; show dbs<\/em><\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26402-body-Picture5_11.png\" alt=\"mongodocker pic 5 \" \/><\/p>\n<p><strong>&nbsp;Conclusion<\/strong><\/p>\n<p>In this post, I created a MongoDB container by using Docker with an attached storage volume from a host system to a container. I also showed you how to start&nbsp;interacting with the MongoDB Docker container through the shell. The post offers&nbsp;a basic demonstration of running a MongoDB instance in a Docker container, but&nbsp;you can use the same MongoDB image to build any number of containers. Use those&nbsp;containers to create replica sets and do much more to create a robust&nbsp;containerized application.<\/p>\n<p>I hope this post helped you to get a general understanding of how to get a&nbsp;MongoDB instance up and running and start working with it in minutes.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Deploy MongoDB as a Docker container<\/p>\n","protected":false},"author":2,"featured_media":7371,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","format":"standard","meta":{"content-type":"","nid":"26402","content_type":"blog","created_by":"10130","authored_on":"2023-12-20T13:34:20+00:00","field_article_industries":"","tag_category":"Technical","field_blog_author_text":"by Rackspace Technology Staff","seo_description":"Migrate from Oracle Internet Directory (OID) to Oracle Unified Directory (OUD). Synchronize with Directory Integration Platform (DIP) and Schemasync.\r\n","field_featured_image":"","insights_image":"\/wp-content\/uploads\/2026\/blog_technical_images\/26402-insights_image-database-technical-blog-2-insights.jpg","field_partners":"","rxt_platforms":"MongoDB","product":"","publisheddate":"2020-03-04T13:34:20","rxt_solutions":"Databases","opengraph_tag":"","x_tag":"","teaser_flag":"Technical Blog","seo_titile":"Deploy MongoDB Docker Container | Rackspace Technology","field_topics":"","field_slug":"deploy-mongodb-as-a-docker-container","footnotes":""},"categories":[178],"tags":[204],"class_list":["post-7369","blogs","type-blogs","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-technical"],"_links":{"self":[{"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/blogs\/7369","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/blogs"}],"about":[{"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/types\/blogs"}],"author":[{"embeddable":true,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/comments?post=7369"}],"version-history":[{"count":3,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/blogs\/7369\/revisions"}],"predecessor-version":[{"id":9423,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/blogs\/7369\/revisions\/9423"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/media\/7371"}],"wp:attachment":[{"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/media?parent=7369"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/categories?post=7369"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/tags?post=7369"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}