Docker Community Forums

Share and learn in the Docker community.

Docker-Compose: There is no official build of MongoDB for Alpine

Hey,

i am kind of new to docker and wanted to try it out to deploy my application. The application consists of database, frontend and backend, each in it’s own container.

So my docker-compose.yml looks like this:

version: "3.8"
services:
  mongodb:
    container_name: modellfabrik_mongodb
    hostname: modellfabrik-db
    image: mongo:4.4
    ports:
      - "27017:27017"
    env_file:
      - .env
    environment:
      MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME}
      MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD}
      MONGO_INITDB_DATABASE: ${MONGO_INITDB_DATABASE}

  backend:
    container_name: modellfabrik_backend
    hostname: modellfabrik-backend
    build: ./server
    depends_on:
      - mongodb
    ports:
      - "3000:3000"
    environment: 
      NODE_ENV: production
      WAIT_HOSTS: modellfabrik-db:27017

  frontend:
    container_name: modellfabrik_frontend
    hostname: modellfabrik-frontend
    build: ./client
    depends_on:
      - backend
    ports:
      - "8080:8080"
    environment: 
      NODE_ENV: production
      WAIT_HOSTS: modellfabrik-backend:3000

Everything works fine, but i noticed when i run docker-compose up i will find this in the logs:

There is no offical build of MongoDB for Alpine!
Falling back to legacy MongoDB build!
Downloading MongoDB 4.0.14: 0 % (0mb / 81.3mb)

I am kind of confused on this message as i didn’t specify Alpine anywhere. Is it some kind of implicit default when using docker-compose? How could i avoid this warning and use an “better” image?

Thanks alot!

I guess the warning came from the backend container, not the mongodb one.
You should try inspecting the Dockerfile inside ./server directory.

1 Like

Thanks alot, you were actually right.

So in the package.json i found a devDependency “mongodb-memory-server”.

{
  "name": "server",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "start": "node server.mjs",
    "test": "mocha -timeout 100000"
  },
  "author": "",
  "license": "ISC",
  "engines": {
    "node": "14.7.0",
    "npm": "6.14.7"
  },
  "dependencies": {
    "apollo-server-express": "^2.18.2",
    "badge-maker": "^3.3.0",
    "cors": "^2.8.5",
    "dotenv": "^8.2.0",
    "express": "^4.17.1",
    "graphql": "^15.3.0",
    "mongoose": "^5.10.9",
    "mongoose-aggregate-paginate-v2": "^1.0.42",
    "nodes7": "^0.3.12"
  },
  "devDependencies": {
    "mocha": "^8.2.1",
    "mongodb-memory-server": "^6.9.2"
  }
}

And the corresponding Dockerfile, which actually uses Alpine:

FROM node:lts-alpine

# Create app directory
WORKDIR /usr/src/app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./

RUN npm install

# Bundle app source
COPY . .

## Add the wait script to the image
ADD wait /wait
RUN chmod +x /wait

EXPOSE 3000

CMD /wait && node server.mjs

So it makes sense the warning is related to the dev-dependency.
What surprises me tho, that the devDependency is installed at all. In my docker-compose i specify

environment: 
      NODE_ENV: production

So the dev-dependencies shouldnt be installed at all. Am i doing something wrong about setting the environment variable?

The Dockerfile instructs Docker how to build the image.
Whatever inside docker-compose.yml (apart from build: section) doesn’t affect the image; instead, it instructs how to augment the container.

You ran npm install with Dockerfile, the environment variables set by docker-compose.yml aren’t gonna affect the npm install in any way.

1 Like

Alright, makes sense. I ended up setting the NODE_ENV inside the Dockerfile.

I wonder, why this wait script can access the environment variables which are set in docker-compose tho.

Well the npm install works as expected now, thanks for your help :slight_smile:

To clarify the last bit of potential misunderstandings.

The wait command was executed inside the container so that it can receive the environment variable set by docker-compose.yml whilst your npm install was executed during image building (no container yet).

1 Like

Makes sense to me now, thanks alot for all the explainations!