Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start mongodb from dockerfile

Tags:

docker

mongodb

I'm building a dockerfile. But I meet a problem. It says that :

/bin/sh: 1: mongod: not found

My dockerfile:

FROM mongo:latest
FROM node

RUN mongod

COPY . .
RUN node ./scripts/import-data.js

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

Any idea ?

like image 601
MathKimRobin Avatar asked Jan 26 '23 04:01

MathKimRobin


1 Answers

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.

* Edit *

here are more details about what is happening:

FROM mongo:latest

  • the base image is mongo:latest

FROM node

  • now the base image is node:latest. The previous image is just standing there...

RUN mongod

COPY . .

RUN node ./scripts/import-data.js

  • now you run mongod and the other commands in your final image that is based on node (which doesn't contain mongo)
like image 160
Adi Fatol Avatar answered Jan 29 '23 09:01

Adi Fatol