Mongodb production of Docker image

In the last chapter. "

Download the installation file mongodb

First To Download mongodb installation file, go to the official website to download, address: https: //www.mongodb.com/download-center#community

After the download directory to find unzip the file, give the folder mongodb-linux-x86_64-ubuntu1604-3.4.9;

Create a file Dockerfile

Dockerfile a new file, and the location mongodb-linux-x86_64-ubuntu1604-3.4.9 in the same directory, the contents Dockerfile shown below, the detailed function of each row see Notes:

# Docker image of hbase cluster	
# VERSION 0.0.1	
# Author: bolingcavalry	
#基础镜像使用ubuntu16.04	
FROM ubuntu:16.04	
#作者	
MAINTAINER BolingCavalry <[email protected]>	
#定义工作目录	
ENV WORK_PATH /usr/local/	
#定义mongodb文件夹名称	
ENV MONGODB_PACKAGE_NAME mongodb-linux-x86_64-ubuntu1604-3.4.9	
#把mongodb安装包从本地电脑复制到工作目录	
COPY ./$MONGODB_PACKAGE_NAME $WORK_PATH/mongodb	
#创建数据库文件目录	
RUN mkdir -p /data/db	
#更新	
RUN apt-get update	
#把libssl.so.1.0.0装上,否则无法运行mongodb	
RUN apt-get install -y libssl1.0.0 libssl-dev	
#把mongodb的bin目录加入到PATH环境变量中	
ENV PATH=$WORK_PATH/mongodb/bin:$PATH	
#mongodb的web端口	
EXPOSE 28017	
#连接端口	
EXPOSE 27017	
#启动服务,--rest参数表示开启web服务	
CMD ["mongod", "--rest"]

Construction of Mirror

Open the console in Dockerfile file directory Run the following command to build the image file, image name bolingcavalry / ubuntu16-mongodb349, tag is 0.0.1:

docker build -t bolingcavalry/ubuntu16-mongodb349:0.0.1 .

Performing apt-get update and apt-get install two command bit consuming, the output successfully constructed substantially as shown below:

640?wx_fmt=png

Create a container verification

Execute the following command to create a container-based building just mirroring:

docker run --name mongo001 -idt -p 28017:28017 bolingcavalry/ubuntu16-mongodb349:0.0.1

Then perform docker exec -it mongo001 / bin / bash into the container, performing mongodb mongo command to enter the console, so as to verify the previous chapter mongodb experience and functions, as shown below:

640?wx_fmt=png

web services

Remember the last few lines of the file it Dockerfile:

#mongodb的web端口	
EXPOSE 28017	
#连接端口	
EXPOSE 27017	
#启动服务,--rest参数表示开启web服务	
CMD ["mongod", "--rest"]

As shown above, the first port 28017 exposed, we run the docker, they also do a port mapping through the -p parameter, and Dockerfile the CMD command also adds a parameter "--rest", with this parameter, you opened mongodb web services, open your browser and enter localhost on the current computer: 28017, and you can see the page shown in the following figure:

640?wx_fmt=png

So far, Docker mirror of our local production mongodb combat is complete, there hub.docker.com account the reader can also docker push command will be pushed to hub.docerk.com local mirror site up, ready to pull into the future.

Published 328 original articles · won praise 946 · Views 1.17 million +

Guess you like

Origin blog.csdn.net/boling_cavalry/article/details/101369293