从Docker官方教程中创buildMongoDB镜像错误

这里是创buildmongoDB img 的官方教程 。

我完全按照教程,并生成了以下Dockerfile

# 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 . 

我得到了以下错误:

在这里输入图像说明

到底是怎么回事? 为什么失败? 如何解决它?

编辑:

调整命令的顺序后,我的最后脚本是这样的:

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

然后我得到以下错误: 在这里输入图像说明

接下来,我添加了“运行apt-get安装sudo”,然后我得到了以下错误:

在这里输入图像说明 在这里输入图像说明

3打击,我不相信这整个事情会起作用。 这是我最后的Dockerfile。

  # 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 # 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 apt-get install sudo # 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,我很想知道我的脚本中有什么问题。 我跟着教程,它不工作。

快速谷歌search你的确切的错误信息发现这一点 。

这是来自apt的错误,它说它找不到它的software-properties-common库中的software-properties-common软件包。 当find一个包更改时,通常意味着需要更新。

您正在运行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命令,它们会抱怨没有find包含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