skip to Main Content

I am getting this error while installing mongodb in docker

[5/6] RUN apk add mongodb=3.4.4-r0:
#8 0.327 ERROR: unable to select packages:
#8 0.328 mongodb (no such package):
#8 0.347 required by: world[mongodb=3.4.4-r0].
executor failed running [/bin/sh -c apk add mongodb=3.4.4-r0]: exit code: 1.

My Dockerfile code is given below which is similar to the StackOverflow solution but it is not working for me.

FROM alpine

RUN echo 'http://dl-cdn.alpinelinux.org/alpine/v3.6/main' >> /etc/apk/repositories
RUN echo 'http://dl-cdn.alpinelinux.org/alpine/v3.6/community' >> /etc/apk/repositories

RUN apk update
RUN apk add mongodb=3.4.4-r0

VOLUME ["/data/db"]
WORKDIR /data
EXPOSE 27017

CMD [ "mongod" ]

2

Answers


  1. You don’t have to add the repositories, just set the alpine version:

    FROM alpine:3.6
    
    ENV TERM=linux
    
    RUN apk add --no-cache bash mongodb=3.4.4-r0
    
    RUN mkdir -p /data/db && 
        chown -R mongodb /data/db
    
    VOLUME /data/db
    EXPOSE 27017
    
    CMD [ "mongod", "--bind_ip", "0.0.0.0"]
    
    Login or Signup to reply.
  2. I hate to be "that guy", but trying to troubleshoot your solution, it just worked on my machine:

    wsl2-ubuntu20.04-screenshot

    Ubuntu 20.04 on WSL2 (Windows 10) with Docker 20.10.17

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search