"Docker" compiles MongoDB image

Source: Internet
Author: User
Tags install mongodb docker run

1. Create a new Dockerfile file

Dockerfile

12345678910111213141516 # VERSION 0.0.1FROM ubuntu:latestMAINTAINER lanhong Turnbull "[email protected]"# Add 10gen official apt source to the sources listRUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10RUN echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | tee /etc/apt/sources.list.d/10gen.list# Hack for initctl not being available in UbuntuRUN dpkg-divert --local --rename --add /sbin/initctlRUN ln -s /bin/true /sbin/initctl# Install MongoDBRUN apt-get updateRUN apt-get install mongodb-10gen# Create the MongoDB data directoryRUN mkdir -p /backup/dockerRepository/mongodb/data/dbEXPOSE 27017ENTRYPOINT ["usr/bin/mongod"]

2. Compile the image and execute the following command in the directory where the Dockerfile is located

1 sudodocker build -t lanhong/mongodb.

3. MongoDB can be run as a management container and can be connected via local port

1234567891011 # Regular styleMONGO_ID=$(sudo docker run -d lanhong/mongodb)# Lean and mean(用这个命令)MONGO_ID=$(sudo docker run -d lanhong/mongodb --noprealloc --smallfiles --dbpath /backup/dockerRepository/mongodb/data/db)# Check the logs outsudo docker logs $MONGO_ID# Connect and play aroundmongod --port <port you get from `docker ps`>

Here MONGO or Mongod command not, let install Apt-get installs mongodb-clients.

To set up the Docker external port, use the following command

1 MONGO_ID=$(docker run -d  -p 5000:27017networld/mongodb --dbpath=/data/db)

This allows you to see two ports in the boot Docker container, and then access the http://serverip:5000

4. Commit (save) the status of the container

Save the container state to the container image so that the state can be reused

12345 # Commit your container to a new named imagesudodocker commit <container_id> <some_name>e.g sudo docker commit afa886fad446 lanhong/mongodb# List your containerssudodocker images


"Docker" compiles MongoDB image

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.