如何从 dockerfile 启动 mongodb [英] How to start mongodb from dockerfile
本文介绍了如何从 dockerfile 启动 mongodb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在构建一个 dockerfile.但是我遇到了一个问题.它说:
I'm building a dockerfile. But I meet a problem. It says that :
/bin/sh: 1: mongod: 未找到
/bin/sh: 1: mongod: not found
我的 dockerfile:
My dockerfile:
FROM mongo:latest
FROM node
RUN mongod
COPY . .
RUN node ./scripts/import-data.js
这是 docker build 时发生的情况:
Here is what happen when docker build:
Sending build context to Docker daemon 829.5MB
Step 1/8 : FROM rabbitmq
---> e8261c2af9fe
Step 2/8 : FROM portainer/portainer
---> 00ead811e8ae
Step 3/8 : FROM docker.elastic.co/elasticsearch/elasticsearch:6.5.1
---> 32f93c89076d
Step 4/8 : FROM mongo:latest
---> 5976dac61f4f
Step 5/8 : FROM node
---> b074182f4154
Step 6/8 : RUN mongod
---> Running in 0a4b66a77178
/bin/sh: 1: mongod: not found
The command '/bin/sh -c mongod' returned a non-zero code: 127
有什么想法吗?
推荐答案
问题是您使用了两个 FROM
指令,称为 多阶段构建
.最终图像将基于不包含 mongo
数据库的 node
图像.
The problem is that you are using two FROM
instructions, which is referred to as a multi-stage build
. The final image will be based on the node
image that doesn't contain the mongo
database.
* 编辑 *
这里有更多关于正在发生的事情的细节:
here are more details about what is happening:
来自 mongo:latest
FROM mongo:latest
- 基础镜像是
mongo:latest
- 现在基础镜像是
node:latest
.上一张图片只是站在那里... - now the base image is
node:latest
. The previous image is just standing there... - 现在您在基于
node
(不包含 mongo)的最终图像中运行mongod
和其他命令 - now you run
mongod
and the other commands in your final image that is based onnode
(which doesn't contain mongo)
来自节点
运行 mongod
复制..
运行节点./scripts/import-data.js
RUN node ./scripts/import-data.js
这篇关于如何从 dockerfile 启动 mongodb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文