本文源链接地址:https://www.93bok.com
1、下载基础镜像centos
docker pull centos:6
2、查看一下大小
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos 6 70b5d81549ec 2 months ago 195MB
3、创建文件夹存放Mongodb的Dockerfile,以及源码包等等,为后期docker-compose做准备
mkdir -p /data/docker/lnmp-test/dockerfile/mongodb
4、创建Mongodb的Dockerfile
vim /data/docker/lnmp-test/dockerfile/mongodb/Dockerfile
FROM centos:6
LABEL maintainer="[email protected]" description="Mongodb image"
COPY mongodb-linux-x86_64-rhel62-3.4.10.tgz /root/mongodb-linux-x86_64-rhel62-3.4.10.tgz
RUN rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 && tar -zxvf /root/mongodb-linux-x86_64-rhel62-3.4.10.tgz && mv mongodb-linux-x86_64-rhel62-3.4.10/ /usr/local/mongodb && mkdir -p /mongodb/data && mkdir -p /mongodb/log && mkdir -p /etc/mongodb && ln -s /usr/local/mongodb/bin/* /usr/local/bin/ && echo "dbpath=/mongodb/data" > /etc/mongodb/mongodb.conf && echo "logpath=/mongodb/log/mongodb.log" >> /etc/mongodb/mongodb.conf && echo "port=27017" >> /etc/mongodb/mongodb.conf && echo "logappend=true" >> /etc/mongodb/mongodb.conf && rm -rf /root/mongodb-linux-x86_64-rhel62-3.4.10.tgz
EXPOSE 27017
CMD ["mongod", "-f", "/etc/mongodb/mongodb.conf"]
5、把mongodb源码包上传到/data/docker/lnmp-test/dockerfile/mongodb/目录下
6、创建镜像
cd /data/docker/lnmp-test/dockerfile/mongodb/
docker build -t centos6:mongodb .
7、查看镜像大小
8、启动容器测试是否成功
docker run -d -p 27017:27017 --name mongodb centos6:mongodb
9、宿主机开启防火墙27017端口
firewall-cmd --add-port=27017/tcp --permanent
systemctl restart firewalld
原文地址:https://www.cnblogs.com/93bok/p/9684848.html
时间: 2024-10-10 20:32:32