简体   繁体   中英

How to install mongodb in docker by writing commands in Dockerfile

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" ]

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"]

I hate to be "that guy", but trying to troubleshoot your solution, it just worked on my machine:

wsl2-ubuntu20.04-截图

Ubuntu 20.04 on WSL2 (Windows 10) with Docker 20.10.17

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM