Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

289
Views
How to start mongodb from dockerfile

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 ?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

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)
over 4 years ago · Santiago Trujillo Report

0

It happens because multiple FROM instructions should be used for Multistage Build (check the documentation) and NOT for image creation contains all of present applications.

Multistage builds provide you possibility of delegation building process into container's environment without local application installation.

FROM rabbitmq

...some instructions require rabbitmq...

FROM mongo:latest

...some instructions require mongo...

In other words if you want to create an image with rabbitmq, mongo and other application you have to choose the image and install applications manually.

over 4 years ago · Santiago Trujillo Report

0

Use docker-compose (https://docs.docker.com/compose/install/) to run the images rather than attempting to build a new image from a collection of existing images. Your docker-compose.yml might look something like:

version: '3.7'
services:
  portainer:
    image: 'portainer/portainer'
    container_name: 'portainer'
    hostname: 'portainer'
    domainname: 'example.com'
    volumes:
    - '/var/run/docker.sock:/var/run/docker.sock'
    - 'portainer_data:/data'
    ports:
    - '9000:9000'
  rabbitmq:
    image: 'rabbitmq'
    container_name: 'rabbitmq'
    hostname: 'rabbitmq'
    domainname: 'example.com'
    volumes:
    - 'rabbitmq_data:/var/lib/rabbitmq'
  elasticsearch:
    image: 'elasticsearch:7.1.1'
    container_name: 'elasticsearch'
    hostname: 'elasticsearch'
    domainname: 'example.com'
    environment:
    - 'discovery.type=single-node'
    volumes:
    - 'elasticsearch_data:/usr/share/elasticsearch/data'
    ports:
    - '9200:9200'
    - '9300:9300'
  node:
    image: 'node:12'
    container_name: 'node'
    hostname: 'node'
    domainname: 'example.com'
    user: 'node'
    working_dir: '/home/node/app'
    environment:
    - 'NODE_ENV=production'
    volumes:
    - './my-app:/home/node/app'
    ports:
    - '3000:3000'
    command: 'npm start'
  mongo:
    image: 'mongo'
    container_name: 'mongo'
    hostname: 'mongo'
    domainname: 'example.com'
    restart: 'always'
    environment:
    - 'MONGO_INITDB_ROOT_USERNAME=root'
    - 'MONGO_INITDB_ROOT_PASSWORD=example'
    volumes:
    - 'mongo_data:/data/db'
volumes:
  portainer_data:
  rabbitmq_data:
  elasticsearch_data:
  mongo_data:
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!