这是the official tutorial创建mongoDB img。
我完全遵循了教程并生成了以下Dockerfile
if(arr1.length == arr2.length && !arr1.some((v) => arr2.indexOf(v) < 0)) {
console.log(true);
} else {
console.log(false);
}
但是当我执行
时# https://docs.docker.com/engine/examples/mongodb/#creating-a-dockerfile-for-mongodb
# Dockerizing MongoDB: Dockerfile for building MongoDB images
# Based on ubuntu:latest, installs MongoDB following the instructions from:
# http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/
# Format: FROM repository[:version]
FROM ubuntu:latest
# Installation:
# Import MongoDB public GPG key AND create a MongoDB list file
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
RUN apt-get install -y --no-install-recommends software-properties-common
RUN echo "deb http://repo.mongodb.org/apt/ubuntu $(cat /etc/lsb-release | grep DISTRIB_CODENAME | cut -d= -f2)/mongodb-org/3.2 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.2.list
# Update apt-get sources AND install MongoDB
RUN apt-get update && apt-get install -y mongodb-org
# MongoDB requires a data directory. Let’s create it as the final step of our installation instructions.
# Create the MongoDB data directory
RUN mkdir -p /data/db
# Expose port 27017 from the container to the host
EXPOSE 27017
# Set usr/bin/mongod as the dockerized entry-point application
ENTRYPOINT ["/usr/bin/mongod"]
我收到以下错误:
发生了什么事?为什么失败?怎么解决?
编辑:
调整命令顺序后,我的最终脚本为:
$ docker build --tag my/repo .
接下来,我添加了#34;运行apt-get install sudo&#34;,然后我收到以下错误:
3击落,我不相信这一切都会奏效。这是我的最终Dockerfile。
# Format: FROM repository[:version]
FROM ubuntu:latest
# Update apt-get sources AND install MongoDB
RUN apt-get update
# Installation:
# Import MongoDB public GPG key AND create a MongoDB list file
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
RUN apt-get install -y --no-install-recommends software-properties-common
# RUN echo "deb http://repo.mongodb.org/apt/ubuntu $(cat /etc/lsb-release | grep DISTRIB_CODENAME | cut -d= -f2)/mongodb-org/3.2 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.2.list
RUN echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
RUN apt-get install -y mongodb-org
# MongoDB requires a data directory. Let’s create it as the final step of our installation instructions.
# Create the MongoDB data directory
RUN mkdir -p /data/db
# Expose port 27017 from the container to the host
EXPOSE 27017
# Set usr/bin/mongod as the dockerized entry-point application
ENTRYPOINT ["/usr/bin/mongod"]
如果你可以使它工作,请粘贴你的Dockerfile,我很想知道我的脚本有什么问题。我按照教程进行操作并不起作用。
答案 0 :(得分:0)
快速搜索您找到this的确切错误消息。
这是apt
的错误,说它无法在其存储库中找到software-properties-common
包。当找到包更改时,通常意味着需要更新。
您正在运行apt-get update
,但在更新行后,您正在运行它。
RUN apt-get install -y --no-install-recommends software-properties-common
...
RUN apt-get update && apt-get install -y mongodb-org
相反,先运行
RUN apt-get update
RUN apt-get install -y --no-install-recommends software-properties-common
...
RUN apt-get install -y mongodb-org
更新:您的更新说您现在在安装mongodb软件包时遇到错误。这是因为您已经加载了deb
包文件,需要再次更新apt以便它知道它。此时,最简单的事情就是为任何apt-get
命令添加前缀,这些命令会抱怨找不到包含update
的包。
RUN apt-get update && apt-get install -y --no-install-recommends software-properties-common
...
RUN apt-get update && apt-get install -y mongodb-org