Working for a consulting firm, I have the opportunity to occasionally explore technologies that don’t quite align with my focus area(s). I started looking at MongoDB, and over the last couple of weeks, I’ve found it to be quite fun. This post will focus on my intro to MongoDB and hopefully will result in a number of posts as I find the time to explore more. To continue my exercises in deploying everything in a Docker Container, let’s take a quick look at this, and then later we can look at connecting to it from a separate container.
While you can find Docker images for MongoDB, what I haven’t found is an image using the Oracle’s Linux Slim version, so let’s go with that.
Create a Dockerfile:
FROM oraclelinux:7-slim ADD mongodb-org-3.4.repo /etc/yum.repos.d/ RUN yum install -y mongodb-org\ && yum clean all RUN mkdir -p /data/db
Create the mongodb-org-3.4.repo.
MongoDB is not included in the YUM repo so we will need to add the mongodb repo to the /etc/yum.repos.d/ directory. In the same directory as the Dockerfile, create the following file: mongodb-org-3.4.repo
[mongodb-org-3.4] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc
That’s it! The only thing remaining is to build and run the image.
In the directory with the Dockerfile and the mongodb-org-3.4.repo file execute the docker build command
Danny: > docker build -t linux_mongo . Sending build context to Docker daemon 4.096kB Step 1/4 : FROM oraclelinux:7-slim 7-slim: Pulling from library/oraclelinux 7bd9e1692b54: Already exists Digest: sha256:f1388709e1ce62dfa9cf9af9746bc0cca47b2e09975a1fb6ba01c66061b2b793 Status: Downloaded newer image for oraclelinux:7-slim ---> 08a01cc7be97 Step 2/4 : ADD mongodb-org-3.4.repo /etc/yum.repos.d/ ---> 49fe0905ce8a Removing intermediate container eaee8071058d Step 3/4 : RUN yum install -y mongodb-org && yum clean all ---> Running in 08e861512242 Loaded plugins: ovl Resolving Dependencies --> Running transaction check ---> Package mongodb-org.x86_64 0:3.4.6-1.el7 will be installed --> Processing Dependency: mongodb-org-tools = 3.4.6 for package: mongodb-org-3.4.6-1.el7.x86_64 --> Processing Dependency: mongodb-org-shell = 3.4.6 for package: mongodb-org-3.4.6-1.el7.x86_64 --> Processing Dependency: mongodb-org-server = 3.4.6 for package: mongodb-org-3.4.6-1.el7.x86_64 --> Processing Dependency: mongodb-org-mongos = 3.4.6 for package: mongodb-org-3.4.6-1.el7.x86_64 --> Running transaction check ---> Package mongodb-org-mongos.x86_64 0:3.4.6-1.el7 will be installed ---> Package mongodb-org-server.x86_64 0:3.4.6-1.el7 will be installed --> Processing Dependency: openssl for package: mongodb-org-server-3.4.6-1.el7.x86_64 ---> Package mongodb-org-shell.x86_64 0:3.4.6-1.el7 will be installed ---> Package mongodb-org-tools.x86_64 0:3.4.6-1.el7 will be installed --> Running transaction check ---> Package openssl.x86_64 1:1.0.1e-60.0.1.el7_3.1 will be installed --> Processing Dependency: openssl-libs(x86-64) = 1:1.0.1e-60.0.1.el7_3.1 for package: 1:openssl-1.0.1e-60.0.1.el7_3.1.x86_64 --> Processing Dependency: make for package: 1:openssl-1.0.1e-60.0.1.el7_3.1.x86_64 --> Running transaction check ---> Package make.x86_64 1:3.82-23.el7 will be installed ---> Package openssl-libs.x86_64 1:1.0.1e-60.el7_3.1 will be updated ---> Package openssl-libs.x86_64 1:1.0.1e-60.0.1.el7_3.1 will be an update --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: mongodb-org x86_64 3.4.6-1.el7 mongodb-org-3.4 5.8 k Installing for dependencies: make x86_64 1:3.82-23.el7 ol7_latest 420 k mongodb-org-mongos x86_64 3.4.6-1.el7 mongodb-org-3.4 12 M mongodb-org-server x86_64 3.4.6-1.el7 mongodb-org-3.4 20 M mongodb-org-shell x86_64 3.4.6-1.el7 mongodb-org-3.4 11 M mongodb-org-tools x86_64 3.4.6-1.el7 mongodb-org-3.4 49 M openssl x86_64 1:1.0.1e-60.0.1.el7_3.1 ol7_latest 713 k Updating for dependencies: openssl-libs x86_64 1:1.0.1e-60.0.1.el7_3.1 ol7_latest 958 k Transaction Summary ================================================================================ Install 1 Package (+6 Dependent packages) Upgrade ( 1 Dependent package) Total download size: 93 M Downloading packages: Delta RPMs disabled because /usr/bin/applydeltarpm not installed. warning: /var/cache/yum/x86_64/7Server/mongodb-org-3.4/packages/mongodb-org-3.4.6-1.el7.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID a15703c6: NOKEY Public key for mongodb-org-3.4.6-1.el7.x86_64.rpm is not installed -------------------------------------------------------------------------------- Total 23 MB/s | 93 MB 00:04 Retrieving key from https://www.mongodb.org/static/pgp/server-3.4.asc Importing GPG key 0xA15703C6: Userid : "MongoDB 3.4 Release Signing Key <packaging@mongodb.com>" Fingerprint: 0c49 f373 0359 a145 1858 5931 bc71 1f9b a157 03c6 From : https://www.mongodb.org/static/pgp/server-3.4.asc Running transaction check Running transaction test Transaction test succeeded Running transaction Updating : 1:openssl-libs-1.0.1e-60.0.1.el7_3.1.x86_64 1/9 Installing : mongodb-org-mongos-3.4.6-1.el7.x86_64 2/9 Installing : 1:make-3.82-23.el7.x86_64 3/9 Installing : 1:openssl-1.0.1e-60.0.1.el7_3.1.x86_64 4/9 Installing : mongodb-org-server-3.4.6-1.el7.x86_64 5/9 /var/tmp/rpm-tmp.y2DUk7: line 3: /usr/bin/systemctl: No such file or directory warning: %post(mongodb-org-server-3.4.6-1.el7.x86_64) scriptlet failed, exit status 127 Non-fatal POSTIN scriptlet failure in rpm package mongodb-org-server-3.4.6-1.el7.x86_64 Installing : mongodb-org-tools-3.4.6-1.el7.x86_64 6/9 Installing : mongodb-org-shell-3.4.6-1.el7.x86_64 7/9 Installing : mongodb-org-3.4.6-1.el7.x86_64 8/9 Cleanup : 1:openssl-libs-1.0.1e-60.el7_3.1.x86_64 9/9 Verifying : mongodb-org-server-3.4.6-1.el7.x86_64 1/9 Verifying : mongodb-org-mongos-3.4.6-1.el7.x86_64 2/9 Verifying : 1:openssl-1.0.1e-60.0.1.el7_3.1.x86_64 3/9 Verifying : 1:openssl-libs-1.0.1e-60.0.1.el7_3.1.x86_64 4/9 Verifying : mongodb-org-3.4.6-1.el7.x86_64 5/9 Verifying : 1:make-3.82-23.el7.x86_64 6/9 Verifying : mongodb-org-tools-3.4.6-1.el7.x86_64 7/9 Verifying : mongodb-org-shell-3.4.6-1.el7.x86_64 8/9 Verifying : 1:openssl-libs-1.0.1e-60.el7_3.1.x86_64 9/9 Installed: mongodb-org.x86_64 0:3.4.6-1.el7 Dependency Installed: make.x86_64 1:3.82-23.el7 mongodb-org-mongos.x86_64 0:3.4.6-1.el7 mongodb-org-server.x86_64 0:3.4.6-1.el7 mongodb-org-shell.x86_64 0:3.4.6-1.el7 mongodb-org-tools.x86_64 0:3.4.6-1.el7 openssl.x86_64 1:1.0.1e-60.0.1.el7_3.1 Dependency Updated: openssl-libs.x86_64 1:1.0.1e-60.0.1.el7_3.1 Complete! Loaded plugins: ovl Cleaning repos: mongodb-org-3.4 ol7_UEKR4 ol7_latest Cleaning up everything ---> bd0c7bcdde6b Removing intermediate container 08e861512242 Step 4/4 : RUN mkdir -p /data/db ---> Running in 518d8adc603b ---> f860503199bd Removing intermediate container 518d8adc603b Successfully built f860503199bd Successfully tagged linux_mongo:latest Danny: >
With the build completed successfully, run the new image and launch the mongoDB server.
Danny: > docker run -it linux_mongo bash-4.2# mongod 2017-07-24T05:17:32.298+0000 I CONTROL [initandlisten] MongoDB starting : pid=7 port=27017 dbpath=/data/db 64-bit host=d3209b3e848a 2017-07-24T05:17:32.299+0000 I CONTROL [initandlisten] db version v3.4.6 2017-07-24T05:17:32.299+0000 I CONTROL [initandlisten] git version: c55eb86ef46ee7aede3b1e2a5d184a7df4bfb5b5 2017-07-24T05:17:32.299+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013 2017-07-24T05:17:32.299+0000 I CONTROL [initandlisten] allocator: tcmalloc 2017-07-24T05:17:32.299+0000 I CONTROL [initandlisten] modules: none 2017-07-24T05:17:32.299+0000 I CONTROL [initandlisten] build environment: 2017-07-24T05:17:32.299+0000 I CONTROL [initandlisten] distmod: rhel70 2017-07-24T05:17:32.299+0000 I CONTROL [initandlisten] distarch: x86_64 2017-07-24T05:17:32.299+0000 I CONTROL [initandlisten] target_arch: x86_64 2017-07-24T05:17:32.299+0000 I CONTROL [initandlisten] options: {} 2017-07-24T05:17:32.303+0000 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=3474M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0), 2017-07-24T05:17:32.335+0000 I CONTROL [initandlisten] 2017-07-24T05:17:32.335+0000 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database. 2017-07-24T05:17:32.335+0000 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted. 2017-07-24T05:17:32.335+0000 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended. 2017-07-24T05:17:32.336+0000 I CONTROL [initandlisten] 2017-07-24T05:17:32.344+0000 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data' 2017-07-24T05:17:32.354+0000 I INDEX [initandlisten] build index on: admin.system.version properties: { v: 2, key: { version: 1 }, name: "incompatible_with_version_32", ns: "admin.system.version" } 2017-07-24T05:17:32.354+0000 I INDEX [initandlisten] building index using bulk method; build may temporarily use up to 500 megabytes of RAM 2017-07-24T05:17:32.355+0000 I INDEX [initandlisten] build index done. scanned 0 total records. 0 secs 2017-07-24T05:17:32.355+0000 I COMMAND [initandlisten] setting featureCompatibilityVersion to 3.4 2017-07-24T05:17:32.356+0000 I NETWORK [thread1] waiting for connections on port 27017
or include it in the command line
Danny: > docker run -it linux_mongo mongod 2017-07-24T05:30:18.000+0000 I CONTROL [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=56bb1cae66fc 2017-07-24T05:30:18.000+0000 I CONTROL [initandlisten] db version v3.4.6 2017-07-24T05:30:18.000+0000 I CONTROL [initandlisten] git version: c55eb86ef46ee7aede3b1e2a5d184a7df4bfb5b5 2017-07-24T05:30:18.000+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013 2017-07-24T05:30:18.000+0000 I CONTROL [initandlisten] allocator: tcmalloc 2017-07-24T05:30:18.000+0000 I CONTROL [initandlisten] modules: none 2017-07-24T05:30:18.000+0000 I CONTROL [initandlisten] build environment: 2017-07-24T05:30:18.000+0000 I CONTROL [initandlisten] distmod: rhel70 2017-07-24T05:30:18.000+0000 I CONTROL [initandlisten] distarch: x86_64 2017-07-24T05:30:18.000+0000 I CONTROL [initandlisten] target_arch: x86_64 2017-07-24T05:30:18.000+0000 I CONTROL [initandlisten] options: {} 2017-07-24T05:30:18.004+0000 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=3474M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0), 2017-07-24T05:30:18.034+0000 I CONTROL [initandlisten] 2017-07-24T05:30:18.034+0000 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database. 2017-07-24T05:30:18.034+0000 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted. 2017-07-24T05:30:18.034+0000 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended. 2017-07-24T05:30:18.034+0000 I CONTROL [initandlisten] 2017-07-24T05:30:18.042+0000 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data' 2017-07-24T05:30:18.053+0000 I INDEX [initandlisten] build index on: admin.system.version properties: { v: 2, key: { version: 1 }, name: "incompatible_with_version_32", ns: "admin.system.version" } 2017-07-24T05:30:18.053+0000 I INDEX [initandlisten] building index using bulk method; build may temporarily use up to 500 megabytes of RAM 2017-07-24T05:30:18.054+0000 I INDEX [initandlisten] build index done. scanned 0 total records. 0 secs 2017-07-24T05:30:18.054+0000 I COMMAND [initandlisten] setting featureCompatibilityVersion to 3.4 2017-07-24T05:30:18.055+0000 I NETWORK [thread1] waiting for connections on port 27017